2

只是徘徊在应用程序设置中输入用户名和密码是否是个好主意?

如果不是,那么存放这些的最佳地点是哪里?

——琼斯

4

2 回答 2

1

由于 web.config 是一个受保护的文件,因此无法直接访问它。您可能会很好地将连接凭据存储在那里。

但是 - 您可以更进一步并在 web.config 中加密 appSettings

演练:使用受保护的配置加密配置信息

于 2010-04-06T08:39:08.687 回答
0

配置文件将是保存有关数据库凭据的详细信息的理想场所。但是,如果您担心其以纯文本形式存储的安全性,那么在 asp.net 中,您可以加密 webconfig 文件的特定部分。加密可以是通过提供相关命令行参数使用 aspnet_regiis.exe 实用程序来完成。否则加密也可以在“ WebConfigurationManager ”类的帮助下通过代码完成。此外,您无需取消保护部分即可读取配置在该部分中设置,运行时将执行您的应用程序读取纯文本值所需的解密。

例如:- aspnet_regiis.exe

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

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

例如:- 使用 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);
}
于 2010-04-06T09:08:02.717 回答