Is there a way to programmatically save values to web.config appSettings without destroying comments and formatting?

喜欢而已 提交于 2019-12-24 03:37:12

问题


This code works, but it destroys comments and formatting in Web.config. Is there a way to write to Web.config that won't destroy formatting?

var webConfig = WebConfigurationManager.OpenWebConfiguration("~");
var settings = webConfig.AppSettings.Settings;
settings["Foo"].Value = "Bar";
webConfig.Save();

回答1:


Maybe you can open the web.config as a standard xml file and use Xpath to locate the node you want to change.




回答2:


You can use Visual Studio API, load Web.config and call Format Document against it



来源:https://stackoverflow.com/questions/4357238/is-there-a-way-to-programmatically-save-values-to-web-config-appsettings-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!