.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"]