/// <summary>
/// 修改web.config文件appsettings配置節(jié)中的add里的value屬性
/// </summary>
/// <remarks>
/// 注意,調(diào)用該函數(shù)后,會(huì)使整個(gè)web application重啟,導(dǎo)致當(dāng)前所有的會(huì)話(huà)丟失
/// </remarks>
/// <param >要修改的鍵key</param>
/// <param >修改后的value</param>
/// <exception cref="">找不到相關(guān)的鍵</exception>
/// <exception cref="">權(quán)限不夠,無(wú)法保存到web.config文件中</exception>
public void ModifyConfig(string path,string key, string strvalue)
{
string xpath = "/configuration/ZFrameConfiguration/add[@key=?]";
XmlDocument domwebconfig = new XmlDocument();
//domwebconfig.Load(HttpContext.Current.Server.MapPath("/web.config"));
domwebconfig.Load(path+"http://file//web.config/");
XmlNode addkey = domwebconfig.SelectSingleNode((xpath.Replace("?", key)));
if (addkey == null)
{
throw new ArgumentException("沒(méi)有找到<add key=" + key + " value=.../>的配置節(jié)");
}
addkey.Attributes["value"].InnerText = strvalue;
//domwebconfig.Save(HttpContext.Current.Server.MapPath("/web.config"));
domwebconfig.Save(path+"http://file//web.config/");
}