动态修改webconfig


 

protected void Application_Start()
{
//读取程序集的配置文件
string assemblyConfigFile = Assembly.GetEntryAssembly().Location;
string appDomainConfigFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//获取appSettings节点
AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
//删除xxx,然后添加新值
appSettings.Settings.Remove("xxx");
appSettings.Settings.Add("xxx", "newValue");

//保存配置文件
config.Save();
//刷新配置文件
ConfigurationManager.RefreshSection("appSettings");
}

 

  

posted @ 2019-01-25 11:21  看那一叶春风  阅读(277)  评论(0编辑  收藏  举报