【问题标题】:Asp.net web application tool - application settings. SQL credentials?Asp.net web 应用程序工具——应用程序设置。 SQL 凭据?
【发布时间】:2010-04-06 07:54:34
【问题描述】:

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

如果不是,最好的存放地点是哪里?

--琼斯

【问题讨论】:

    标签: asp.net application-settings


    【解决方案1】:

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

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

    Walkthrough: Encrypting Configuration Information Using Protected Configuration

    【讨论】:

    • 感谢 web.conf 已经足够好了。我实际上虽然你可以访问 web.conf?
    【解决方案2】:

    配置文件将是保存有关数据库凭据的详细信息的理想场所。但是,如果您担心其以纯文本形式存储的安全性,那么在 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);
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 2011-05-21
      • 2011-03-09
      • 2010-10-26
      • 2012-11-30
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      相关资源
      最近更新 更多