我正在使用来自 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();
}