日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Configuration类在网页实现对web.config的修改[转]

發布時間:2025/7/14 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Configuration类在网页实现对web.config的修改[转] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

【IT168技術文檔】?

? 一、ConfigurationManager.OpenExeConfiguration的問題?
? ConfigurationManager.OpenExeConfiguration有兩個重載,?
? ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)和ConfigurationManager.OpenExeConfiguration(Server.MapPath("web.config"));?

? 經過實驗我發現,在網上上,ConfigurationManager.OpenExeConfiguration?(ConfigurationUserLevel.PerUserRoamingAndLocal)不能使用,而Configuration和 ConfigurationManager.OpenExeConfiguration其實不能直接對文件進行修改。

Configuration cfg = ConfigurationManager.OpenExeConfiguration(Server.MapPath("web.config")); Response.Write(cfg.FilePath);

? 你會發現以上代碼輸出的FilePath是F:\路徑\Web\web.config.config 。打開的文件雖然看的是web.config,其實是另外一個文件web.config.config,雖然web.config.config并不存在。?

? 而進行以下操作

Configuration cfg = ConfigurationManager.OpenExeConfiguration(Server.MapPath("web.config")); cfg.AppSettings.Settings.Remove("123"); cfg.AppSettings.Settings.Add("123","asdasd"); cfg.Save();

? 讀不出web.config的內容,而實際上是讀的web.config.config的內容。我們現在沒這個文件,那么內容就是空的。保存之后,得到

<?xml version="1.0" encoding="utf-8"?><configuration><appSettings><add key="123" value="asdasd"/></appSettings></configuration>

? 二、引出來的思路?
? 可以建立個文件web.config.config,作為web.config的副本。?
? 再次執行

Configuration cfg = ConfigurationManager.OpenExeConfiguration(Server.MapPath("web.config")); cfg.AppSettings.Settings.Remove("123"); cfg.AppSettings.Settings.Add("123","asdasd"); Response.Write(cfg.FilePath); cfg.SaveAs(Server.MapPath("web.config"));

? 操作,則確實實現了對文件的修改。

?

【原地址】:http://tech.sina.com.cn/s/2008-06-30/1013712947.shtml

轉載于:https://www.cnblogs.com/yongtaiyu/p/3594182.html

總結

以上是生活随笔為你收集整理的Configuration类在网页实现对web.config的修改[转]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。