使用的加密/解密方法具体web.config文件 似乎仍然是首选的做法 Classic implementation programmatically 我不认为加密的web.config的做法已与MVC更新,比其他的,很明显,您不能使用事件按钮来调用上述示例中的方法。您想要将加密/解密方法映射到控制器操作。
public ActionResult Encrypt()
{
ProtectSection("connectionStrings", "RSAProtectedConfigurationProvider");
return View();
}
private void ProtectSection(string sectionName,
string provider) {
Configuration config =
WebConfigurationManager.
OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section =
config.GetSection(sectionName);
if (section != null &&
!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}}
见http://www.asp.net/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure其中显示了如何将PW移出web.config – RickAndMSFT