动态修改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"); }
不忘初心