asp.net 对 xml webconfig的操作

 XmlDocument xdc = new XmlDocument();
  xdc.Load(Server.MapPath("Web.config"));
     XmlNode root = xdc.SelectSingleNode("configuration/appSettings/add");
  XmlElement xe = root as XmlElement;
  xe.SetAttribute("value","server=.;database=pubs;user id=sa;password=");
   xe.InnerText="tesstadd";
   xdc.Save(Server.MapPath("Web.config"));
  Response.Write(xe.GetAttribute("key")); 

 

    Dim xdc As XmlDocument = New XmlDocument
        xdc.Load(Request.PhysicalApplicationPath + ("web.xml"))
        Dim xn As XmlNode = xdc.SelectSingleNode("root/config/pc")
        Dim xe As XmlElement = CType(xn, XmlElement)
        xe.GetAttribute("name")
        xe.GetAttribute("ip")
        xe.GetAttribute("open")
        Dim ip As String = xe.GetAttribute("ip")
        Dim open As String = xe.GetAttribute("open")
        If open = "yes" Then
        Else
            Response.Redirect(Request.Url.ToString())
        End If

你可能感兴趣的:(asp.net)