以编程方式编辑Web.config [英] Editing Web.config programmatically

查看:70
本文介绍了以编程方式编辑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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆