2011-11-07 80 views
1

我必须部署一个asp.net mvc 3网站,其web.config包含数据库凭证。asp.net mvc 3 web.config连接字符串加密

搜索一段时间后,我发现有一个可以放置在连接字符串中的App_Data文件夹一个cs文件,但如果数据库密码已更改,那么该网站需要重新编译。

而且我得到了这个链接: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA,但该页面表示,内容未退休。

有人可以告诉更新的做法来加密web.config文件中的连接字符串信息。

谢谢。

+0

见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

回答

2

使用的加密/解密方法具体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(); 
}} 
+0

这在3年前可能是正确的,但首选的做法是将其移出。请参阅http://www.asp.net/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure – RickAndMSFT

相关问题