编辑Web.config文件编程 [英] Editing Web.config programatically
本文介绍了编辑Web.config文件编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是编程编辑Web.config文件的好方法?
What is a good way to edit a Web.config file programatically?
我看着的System.Xml,但找不到任何明显的答案。
I looked into System.Xml but couldn't find any obvious answers.
推荐答案
这老乡显示样品code,如果你仍然希望所有的注意事项之后做到这一点:
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屋!
查看全文