Modify("Count",this.txtCount.Text.Trim());
/// <summary>
/// 修改web.config文件appsettings配置節中的add裏的value屬性
/// </summary>
/// <remarks>
/// 注意,調用該函數後,會使整個web application重啓,致使當前全部的會話丟失 /// </remarks>
/// <param name="key">要修改的鍵key</param>
/// <param name="strvalue">修改後的value</param>
/// <exception cref="">找不到相關的鍵</exception>
/// <exception cref="">權限不夠,沒法保存到web.config文件中</exception>
private void Modify(string key,string strvalue)
{
string xpath = "/configuration/appSettings/add[@key=''Count'']";
XmlDocument domwebconfig = new XmlDocument();
domwebconfig.Load(HttpContext.Current.Server.MapPath("/web.config"));
XmlNode addkey = domwebconfig.SelectSingleNode((xpath.Replace("Count", key)));
if (addkey == null)
{
throw new ArgumentException("沒有找到<add key=" + key + " value=.../>的配置節");
}
addkey.Attributes["value"].InnerText = strvalue;
domwebconfig.Save(HttpContext.Current.Server.MapPath("/web.config"));
}web