【问题标题】:How to store accounts access informations inside ASP.NET application如何在 ASP.NET 应用程序中存储帐户访问信息
【发布时间】:2011-03-06 23:44:31
【问题描述】:

我需要在我的 asp.net 应用程序中保留对不同网页的访问设置。这些设置是这些页面的登录名和密码。将它们保存在部分的 web.config 中是否足够安全?

【问题讨论】:

  • 您能详细说明一下吗?你的意思是页面允许的角色?为什么要将登录名和密码存储到 web.config 中的各个页面?您可以使用 Forms Authentication 对用户进行身份验证,然后通过 web.config 设置对用户进行授权。
  • 考虑为每个页面使用角色而不是多个用户/密码设置。如果您使用 ASP.NET MVC - 区域的概念就可以了。在典型的 ASP.NET 世界中,您可以使用文件夹来分隔页面。
  • 我的意思是完全访问其他服务。假设我有一些房子,公寓提供,我需要通过 FTP 以压缩文件的形式在专用服务上导出。我需要保留所有这些服务的登录名和密码设置。

标签: c# asp.net security


【解决方案1】:

是的,您可以在 web.config 中保留登录信息和密码,并且可以通过加密来保护这些部分。我不知道这是否是最合适的地方,但根据您的描述,我认为这是您的情况的最佳解决方案。

这是一种实现加密的可靠方法:What is the proper method for encrypting ASP.NET connetionStrings?

private void ProtectSection(string sectionName,
                                   string provider)
{
    Configuration config =
        WebConfigurationManager.
            OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section =
                 config.GetSection(sectionName);

    if (section != null &&
              !section.SectionInformation.IsProtected)
    {
        section.SectionInformation.ProtectSection(provider);
        config.Save();
    }
}

private void UnProtectSection(string sectionName)
{
    Configuration config =
        WebConfigurationManager.
            OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section =
              config.GetSection(sectionName);

    if (section != null &&
          section.SectionInformation.IsProtected)
    {
        section.SectionInformation.UnprotectSection();
        config.Save();
    }
}

因此,要保护设置,您只需调用 ProtectSection 方法,并使用您希望保护的部分和您选择的保护提供者(通常是 DataProtectionConfigurationProviderRSAProtectedConfigurationProvider):

ProtectSection("appSettings", "DataProtectionConfigurationProvider");

要取消保护部分,您可以使用要取消保护的部分调用 UnProtectSection 方法:

UnProtectSection("appSettings");

【讨论】:

    猜你喜欢
    • 2016-06-16
    • 2022-10-06
    • 1970-01-01
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    相关资源
    最近更新 更多