动态配置WebC.Config
采用Linq
string xmlPath = Server.MapPath("/web.config"); XElement rootNode = XElement.Load(xmlPath); var custs = (from c in rootNode.Elements("appSettings").Elements("add") select c).ToList(); foreach (XElement node in custs) { if (node.Attribute("key").Value == "routeaa") { node.Attribute("value").SetValue("Question/{id}"); } } rootNode.Save(xmlPath);