And*_*ehm 11 vb.net asp.net web-config
以编程方式编辑Web.config文件的好方法是什么?
我查看了System.Xml但找不到任何明显的答案.
DOK*_*DOK 13
这个人显示示例代码,如果您仍想在所有警告之后执行此操作:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑web.config的一个正当理由是加密它,这就是那篇文章的内容.