我正在使用Windows Azure的共享網站。我想加密我的web.config部分,但是,我收到此錯誤:加密Web.config Windows Azure
未能使用提供程序'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();
}
我不確定你是如何加密/解密的,但Azure中的機器密鑰將與本地不同。我相信每個實例都會有不同的機器密鑰。所以,無論你如何加密,你都必須牢記這一點。你能提供更多關於你如何做這種加密/解密的信息嗎? – Jaxidian 2013-02-25 04:12:00
我添加了一些新的代碼,謝謝。我注意到加密的代碼工作了幾個小時,然後就休息了。看來我的代碼被髮送到一個新的實例,它有它的關鍵。 – 2013-02-25 17:04:24