痛快-Web.Config配置

动态配置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);

 

posted @ 2013-10-03 12:13  痛快  阅读(145)  评论(0编辑  收藏  举报