7

我正在使用来自 Windows Azure 的共享网站。我想加密我的 web.config 的一部分,但是,我收到了这个错误:

无法使用提供程序“RsaProtectedConfigurationProvider”解密。来自提供程序的错误消息:无法打开 RSA 密钥容器。

我的网站中有一个页面可以加密该文件,并且确实如此,但是,几个小时后我收到了这个错误。我需要将我的机器密钥发送到 Azure 还是他们有一个我可以使用?

要加密我的配置文件,我使用以下代码:

    /// <summary>
    /// About view for the website.
    /// </summary>
    /// <returns>Action Result.</returns>
    public ActionResult About()
    {
        Configuration objConfig =
          WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        AppSettingsSection objAppsettings =
          (AppSettingsSection)objConfig.GetSection("appSettings");
        if (!objAppsettings.SectionInformation.IsProtected)
        {
            objAppsettings.SectionInformation.ProtectSection(
                           "RsaProtectedConfigurationProvider");
            objAppsettings.SectionInformation.ForceSave = true;
            objConfig.Save(ConfigurationSaveMode.Modified);
        }

        return View();
    }
4

2 回答 2

4

它可能不是您要查找的内容,但您可以使用 Azure 仪表板中的“配置”选项卡在运行时覆盖 AppSettings,这样 web.config 就不会存储任何实际的敏感数据。

http://www.windowsazure.com/en-us/manage/services/web-sites/how-to-configure-websites/#howtochangeconfig

应用程序设置 - 指定将由您的 Web 应用程序在启动时加载的名称/值对。对于 .NET 站点,这些设置将在运行时注入到您的 .NET 配置 AppSettings 中,覆盖现有设置。对于 PHP 和 Node 站点,这些设置将在运行时作为环境变量提供。

于 2013-03-11T18:20:08.863 回答
2

我不确定在您提出问题时这是否可用,但是 Microsoft 的一位工程师为 Windows Azure 提出了一个新的 ProtectedConfigurationProvider。这是它的链接:https ://code.msdn.microsoft.com/Encrypt-Configuration-5a8e8dfe#content 。

他们已经提供了详细的步骤,说明在此处应该做什么。

于 2015-01-02T10:31:19.437 回答