2010-04-06 73 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); 
}