/// <summary>
/// 修改 Web.Config 中 appSettings 节点内节点信息
/// </summary>
/// <param name="nodeName">节点名</param>
/// <param name="nodeKey">节点值</param>
/// <returns>返回操作逻辑值</returns>
public static bool SetWebConfigValue(string nodeName, string nodeKey)
{
string filename = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath + "/web.config");
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(filename);
System.Xml.XmlNode node = xmldoc.SelectSingleNode("configuration//appSettings");
System.Xml.XmlNodeList nl = node.ChildNodes;
foreach (XmlNode el in nl)
{
try
{
if (el.Attributes["key"].Value == nodeName)
{
el.Attributes["value"].Value = nodeKey;
}
}
catch
{
}
}
try
{
xmldoc.Save(filename);
return true;
}
catch
{
return false;
}
}