修改web.config文件appsettings配置节

来源:互联网 发布:淘宝刷好评会被判刑吗 编辑:程序博客网 时间:2024/05/29 10:10
 
''修改web.config文件appsettings配置节中的add里的属性 
    ''调用该函数后,会使整个web application重启,导致当前所有的会话丢失 
    ''<param name="key">要修改的键key</param> 
    ''<param name="str">修改后的</param>    
    Sub WriteConnStr(ByVal key As StringByVal str As String)
        
Dim xpath As String = "/configuration/appSettings/add[@key=""" + key + """]"
        
Dim WebConfig As New System.Xml.XmlDocument

        WebConfig.Load(HttpContext.Current.Server.MapPath(
"web.config"))
        
Dim addkey As System.Xml.XmlNode = WebConfig.SelectSingleNode(xpath)

        
If addkey IsNot Nothing Then
            addkey.Attributes(
"value").InnerText = str
            WebConfig.Save(HttpContext.Current.Server.MapPath(
"web.config"))
        
End If
    
End Sub