【发布时间】:2010-04-06 07:54:34
【问题描述】:
在应用程序设置中输入用户名和密码是否是个好主意?
如果不是,最好的存放地点是哪里?
--琼斯
【问题讨论】:
标签: asp.net application-settings
在应用程序设置中输入用户名和密码是否是个好主意?
如果不是,最好的存放地点是哪里?
--琼斯
【问题讨论】:
标签: asp.net application-settings
由于 web.config 是一个受保护的文件,因此无法直接访问它。在那里存储连接凭据可能会很好。
但是 - 您可以更进一步,在 web.config 中加密 appSettings
Walkthrough: Encrypting Configuration Information Using Protected Configuration
【讨论】:
配置文件将是保存有关数据库凭据的详细信息的理想场所。但是,如果您担心其以纯文本形式存储的安全性,那么在 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);
}
【讨论】: