【问题标题】:Overwrite ConnectionString in web.config ASP.NET MVC覆盖 web.config ASP.NET MVC 中的 ConnectionString
【发布时间】:2013-10-15 09:49:04
【问题描述】:

我正在尝试加密部分 web.config 文件。(密码) 这对于像这样的普通 Section-Keys 很有效:

<AppSettings>
    <add key="SomePassword" value="HI I AM ENCRYPTET"/>
<AppSettings>

在 Global.asax 中,我执行以下操作:

System.Configuration.ConfigurationManager.AppSettings["SomePassword"] = Decrypt(System.Configuration.ConfigurationManager.AppSettings["SomePassword"])

这很好用。但是当我为 Connection-String 尝试这个时,会抛出一个异常:“配置是只读的。”

所以,我没有权利写。有人知道如何在不编辑 Connection-String 类的情况下解决这个问题吗?

感谢和问候

【问题讨论】:

    标签: c# asp.net-mvc web-config connection-string


    【解决方案1】:

    您可以通过以下方式将机密从 web.config 文件中移出:

    <appSettings file="..\..\AppSettingsSecrets.config"> 
    

    请参阅将密码和其他敏感数据部署到 ASP.NET 和 Azure 网站的最佳做法。 http://www.asp.net/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure

    对于 Azure,我喜欢使用 http://www.powershellcookbook.com/recipe/PukO/securely-store-credentials-on-disk 将凭据加密到磁盘。

    【讨论】:

      猜你喜欢
      • 2011-07-21
      • 2020-01-23
      • 2011-10-01
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 2011-02-11
      相关资源
      最近更新 更多