【问题标题】:web.config in asp.net在 asp.net 中的 web.config
【发布时间】:2010-07-29 05:44:50
【问题描述】:

我想在 web.config 中提供来自数据库的用户名、密码和 APIKey 的值。意味着无论管理员设置的用户名、密码、APIkey 必须在 web.config 中设置。 我怎样才能改变这个。任何想法。

谢谢。

【问题讨论】:

    标签: asp.net


    【解决方案1】:
     private void UpdateConfig(string strKey, string strValue)
    {
       Configuration objConfig =
          WebConfigurationManager.OpenWebConfiguration("~");
       AppSettingsSection objAppsettings =
          (AppSettingsSection)objConfig.GetSection("appSettings");
       if (objAppsettings != null)
       {
          objAppsettings.Settings[strKey].Value = strValue;
          objConfig.Save();
       }
    }
    

    但是每次更新 web.config 文件都会重启你的应用域,所以不建议频繁更新 web.config。

    请参考:Editing Web.config programatically

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2011-04-23
      • 1970-01-01
      • 2011-02-07
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      相关资源
      最近更新 更多