关于修改Web配置文件的方法记录
以前都是直接解析Web.config来操作,现在发现可以这样做,
//打开配置文件
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
//获取appSettings节点
AppSettingsSection appSection = (AppSettingsSection)config.GetSection("appSettings");
//删除appSettings节点中的元素
appSection.Settings.Remove("addkey1");
//修改appSettings节点中的元素
appSection.Settings["addkey2"].Value = "Modify key2's value";
config.Save();

浙公网安备 33010602011771号