.NET CORE获取appsettings.json的字符串

//添加AppsettingJson类

  //获取appsettings的json字符串
    public class AppSettingsJson
    {
        public static IConfiguration Configuration { get; set; }

        static AppSettingsJson()
        {
            //ReloadOnChange = true 当appsettings.json被修改时重新加载            
            Configuration = new ConfigurationBuilder()
            .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
            .Build();
        }
    }

//获取Config字符串

string Connection = AppSettingsJson.Configuration.GetConnectionString("Connection");

你可能感兴趣的:(.NETCORE,.netcore)