1. 程式人生 > >.net core獲取appsettings CustomSettings

.net core獲取appsettings CustomSettings

collect warn .net core spa emp ets reload ret new

private static string GetCustomSettings(string key)
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json", optional: true
, reloadOnChange: true) .Build(); return config.GetSection("CustomSettings").GetValue(key, string.Empty); } // 獲取自定義value public static string WXWarningClosedTemplateID => GetCustomSettings("xxx");

.net core獲取appsettings CustomSettings