会员提供商遇到麻烦

时间:2010-11-26 09:31:18

标签: asp.net web-config

我在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-&gt; 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)

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

1 个答案:

答案 0 :(得分:0)

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

我相信您会从会员提供商和角色提供商处删除applicationName