只是想知道在应用程序设置中放置用户名和密码是否是个好主意?
如果不是哪里存放这些产品的最佳位置?
- Jonesy
答案 0 :(得分:1)
由于web.config是受保护的文件,因此无法直接访问它。你可能会很好地存储你的连接凭据。
但是 - 您可以更进一步加密web.config中的appSettings
Walkthrough: Encrypting Configuration Information Using Protected Configuration
答案 1 :(得分: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);
}