以编程方式编辑 Web.config [英] Editing Web.config programmatically
本文介绍了以编程方式编辑 Web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以编程方式编辑 Web.config 文件的好方法是什么?
What is a good way to edit a Web.config file programmatically?
我查看了 System.Xml,但找不到任何明显的答案.
I looked into System.Xml but couldn't find any obvious answers.
推荐答案
这个家伙 展示了示例代码,如果你在所有警告之后仍然想这样做:
This fellow shows sample code if you still want to do it after all the caveats:
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 的一个正当理由是对其进行加密,这就是那篇文章的内容.
One valid reason for editing a web.config is to encrypt it, which is what that article is about.
这篇关于以编程方式编辑 Web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文