.net core的startup中配置读取

 public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            Configuration = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)  
                .AddEnvironmentVariables()
                .Build();
        }
        public IConfiguration Configuration { get; }

读取配置信息

Configuration.GetSection("AppConfig")["DbConn"]

 

posted @ 2019-10-25 11:36  向萧  阅读(900)  评论(0编辑  收藏  举报