c# Initialize Appsettings from database

风流意气都作罢 提交于 2019-12-02 04:45:45

Since I did not recieve any answers, I ended up doing a POC to prove my point, below is the piece of code which goes through the appsettings and updates settings from DB:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

IDictionary<string, string> staticAppSettings = ConfigService.GetStaticAppSettings(); // DB Call to get all settings from DB

foreach (var setting in staticAppSettings)
{
  if (ConfigurationManager.AppSettings[setting.Key] == null)
    config.AppSettings.Settings.Add(setting.Key, setting.Value);
  else
    ConfigurationManager.AppSettings[setting.Key] = setting.Value; // Update existing
}

config.Save();
ConfigurationManager.RefreshSection("appSettings");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!