2010-04-06 61 views

回答

0

的配置文件将是一个理想的地方保存有关数据库credential.But的细节,如果你是担心其存储在纯文本中的安全性,然后在asp.net中,您可以加密webconfig文件的特定部分.Encyption可以通过提供相关命令行参数来使用aspnet_regiis.exe实用程序完成。否则,加密可以也可以通过代码在“WebConfigurationManager”的帮助下完成。您还可以为了读取该部分中的配置设置,不需要解除部分的保护,运行时将执行解密,以便应用程序读取纯文本值。

E.g: - ASPNET_REGIIS.EXE

C:\>aspnet_regiis -pdf "connectionStrings" "C:\Projects\My Site" 

这里PDF参数用于指定文件路径。

E.g: - 使用WebConfigurationManager

protected void toggleEncryption(object sender, EventArgs e) 
{ 
    Configuration config; 
    config = WebConfigurationManager.OpenWebConfiguration("~"); 
    ConnectionStringsSection section; 
    section = config.GetSection("connectionStrings") 
     as ConnectionStringsSection; 
    if (section.SectionInformation.IsProtected) 
    { 
     section.SectionInformation.UnprotectSection(); 
    } 
    else 
    { 
     section.SectionInformation.ProtectSection(
      "DataProtectionConfigurationProvider"); 
    } 
    config.Save(); 
    WriteMessage("connections protected = " + 
    section.SectionInformation.IsProtected); 
}