Asp.net
以程式方式編輯 Web.config
以程式方式編輯 Web.config 文件的好方法是什麼?
我查看了 System.Xml 但找不到任何明顯的答案。
如果您仍然想在所有警告之後這樣做,這個傢伙會顯示範常式式碼:
protected void EditConfigButton(object sender, EventArgs e) { Configuration objConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings"); //Edit if (objAppsettings != null) { objAppsettings.Settings["test"].Value = "newvalueFromCode"; objConfig.Save(); } }編輯 web.config 的一個正當理由是對其進行加密,這就是那篇文章的內容。