大家好,小淋來為大家解答以上問題。白條錦蛇,btjson很多人還不知道,現在讓我們一起來看看吧!
代碼如下:請導入系統。可擴展置標語言命名空間
字符串文件=服務器MapPath(@ ' ~ \ web。config’);
XML文檔XML doc=new XML document();
xmlDoc .加載(文件);
字符串s1=' aaa
字符串s2=' bbb
字符串h=' ccc
字符串用戶=' ddd
字符串傳遞=' eee
XmlNodeList節點列表=null
nodeList=xmlDoc .SelectSingleNode('配置//連接字符串').子節點;
//遍歷所有子節點
foreach(節點列表中的XmlNode xn)
{
//將子節點類型轉換為元素對象類型
XmlElement xe=xn as XmlElement
如果(xe .Name=='add ')
{
如果(xe .GetAttribute(' name ')==' acountConnectionString ')
{
xe .SetAttribute('connectionString ',S1);
}
如果(xe .獲取屬性('名稱')=='郵件地址')
{
xe .SetAttribute('connectionString ',S2);
}
}
}
nodeList=xmlDoc .SelectSingleNode(' configuration//system。net//郵件設置//SMTP’).子節點;
foreach(節點列表中的XmlNode xn)
{
//將子節點類型轉換為元素對象類型
XmlElement xe=xn as XmlElement
如果(xe .Name=='network ')
{
xe .SetAttribute('host ',h);
xe .SetAttribute('用戶名,用戶);
xe .SetAttribute('password ',pass);
打破;
}
}
xmlDoc .保存(文件);
但實際上通過代碼修改網頁配置的操作微乎其微
1.網頁配置的修改可能會導致會議等服務器變量的丟失
2.如果你的頁面是發布在(同移民檢查員移民檢查)下面,要通過頁面修改網頁配置必須給網頁配置這個文件添加網絡服務(IIS6)或ASPNET (IIS)用戶的寫權限,這在實際操作中是不可想象的
本文到此結束,希望對大家有所幫助。