/// <summary>
/// 修改web.config文件appsettings配置節(jié)中的add里的value屬性
/// </summary>
/// <remarks>
/// 注意,調用該函數(shù)后,會使整個web application重啟,導致當前所有的會話丟失
/// </remarks>
/// <param >要修改的鍵key</param>
/// <param >修改后的value</param>
/// <exception cref="">找不到相關的鍵</exception>
/// <exception cref="">權限不夠,無法保存到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("沒有找到<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/");
}