我正在使用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();
}
Run Code Online (Sandbox Code Playgroud)
它可能不完全是您正在寻找的内容,但您可以使用 Azure 仪表板中的“配置”选项卡在运行时覆盖 AppSettings,以便 web.config 不会存储任何实际的敏感数据。
\n\n\n\n\n\n应用程序设置 \xe2\x80\x93 指定 Web 应用程序在启动时加载的名称/值对。对于 .NET 站点,这些设置将在运行时注入到您的 .NET 配置 AppSettings 中,从而覆盖现有设置。对于 PHP 和 Node 站点,这些设置将在运行时作为环境变量提供。
\n
归档时间: |
|
查看次数: |
1579 次 |
最近记录: |