【问题标题】:Trouble with membership providers会员供应商的麻烦
【发布时间】:2010-11-26 09:31:17
【问题描述】:

我在 ASP.NET 4.0 成员资格方面遇到了一些问题。我想在我的 web.config 文件中拥有我的所有成员资格配置,而不是使用 machine.config。我将成员资格存储在名为 MYSERVER\A 的远程 SQL Server 2008 R2 数据库服务器中。这是web.config的相关部分

<connectionStrings>
    <clear/>
    <add name="MarksDB" connectionString="Server=MYSQLSERVER\A;Database=test_d; Trusted_Connection=Yes; Application Name=MarksDB"/>
</connectionStrings>
<system.web>

<authorization>
   <allow roles="Admins" />
   <deny users="?" />
</authorization>
<authentication mode="Forms">
   <forms name="MarksDB" />
</authentication>
<membership defaultProvider="MarksDBMembershipProvider">
  <providers>
    <clear/>
    <add 
      name="MarksDBMembershipProvider" 
      type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      connectionStringName="MarksDB" 
      enablePasswordRetrieval="false" 
      enablePasswordReset="true" 
      requiresQuestionAndAnswer="true" 
      applicationName="MarksDBMembershipProvider" 
      requiresUniqueEmail="false" 
      passwordFormat="Hashed" 
      maxInvalidPasswordAttempts="5" 
      minRequiredPasswordLength="7" 
      minRequiredNonalphanumericCharacters="1" 
      passwordAttemptWindow="10" 
      passwordStrengthRegularExpression=""/>

  </providers>
</membership>

<roleManager enabled="true" defaultProvider="MarksDBRoleProvider">
  <providers>
    <clear/>
    <add 
        name="MarksDBRoleProvider"
        type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        connectionStringName="MarksDB"
        applicationName="MarksDBRoleProvider"
        />        
  </providers>      
</roleManager>

在 Visual Studio 2010 中,当我转到 WebSite->ASP.NET 配置,然后单击安全选项卡上的添加用户时,我收到此错误:

An error was encountered. Please return to the previous page and try again.

The following message may help in diagnosing the problem: The connection name 'MarksDB' was not found in the applications configuration or the connection string is empty. at System.Web.Util.SecUtility.GetConnectionString(NameValueCollection config) at System.Web.Security.SqlMembershipProvider.Initialize(String name, NameValueCollection config) at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)

我不确定如何解决此问题。有什么想法吗?

【问题讨论】:

    标签: asp.net web-config


    【解决方案1】:

    您应该在成员资格提供程序和角色管理器中使用applicationName 属性来指定您的应用程序(因为您可以有另一个应用程序使用相同的数据库)。但是您在连接字符串中指定了Application Name

    我相信您会从会员提供者和角色提供者中删除 applicationName

    【讨论】:

    • 我从我的 web.config 中的成员资格提供程序和角色提供程序中删除了 applicationName 属性,但是当我单击创建用户时仍然收到相同的错误。
    • 我恢复了 machine.config,现在一切正常。奇怪,因为我没有从那里读到任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多