string path = Server.MapPath("~/Web.config");
//"Web.config";
var xml = XElement.Load(path);
var temp = from k in xml.Descendants("appSettings").Elements("add")
where k.Attribute("key").Value == "pas"
select k;
var query = temp.SingleOrDefault();
if (query != null)
{
query.Attribute("value").Value = newpassword;
xml.Save(path);
}
本文介绍了一种使用C#从Web.config文件中读取并更新特定配置的方法。通过LINQ to XML技术定位到appSettings中的指定键,并修改其对应的值。
430

被折叠的 条评论
为什么被折叠?



