0

我在 ASP.NET 4.5 网络表单中使用新的登录控件,需要根据我的 SQL 成员资格提供程序检查用户名和密码。我已经设置了成员资格和角色,并通过 Web 应用程序工具创建了我的用户。

当我尝试登录时,我的用户名和密码未针对会员提供者进行身份验证。以下是 web.confgi 中的相关条目:

   <membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <add connectionStringName="WebTrendsConnectionString" enablePasswordRetrieval="false"
      enablePasswordReset="true" requiresQuestionAndAnswer="false"
      requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
      minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
      applicationName="/" name="DefaultMembershipProvider" 
      type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, 
      Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="DefaultRoleProvider">
  <providers>
    <add connectionStringName="DefaultConnection" applicationName="/"
      name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, 
      System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</roleManager>

更新:仍然无法使用 WSAT 中创建的用户名和密码登录。这是我的连接字符串和提供者:

<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=PKFDB0;Initial Catalog=WebTrends; 
Integrated Security=False; User ID=*****; Password=******;" 
providerName="System.Data.SqlClient"/>

 <membership>
  <providers>
    <add connectionStringName="LocalSqlServer" enablePasswordRetrieval="true"
      enablePasswordReset="true" requiresQuestionAndAnswer="false"
      requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6"
      minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
      applicationName="/" name="DefaultMembershipProvider" 
      type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, 
      Version=1.0.0.0, 
      Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</membership>
<roleManager enabled="true">
  <providers>
    <add connectionStringName="LocalSqlServer" applicationName="/"
      name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, 
      System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </providers>
</roleManager>
4

3 回答 3

2

Your membership and roleManager should use same connection string, unless you are validating against two databases - user db and role db - which is not common.

connectionStringName="WebTrendsConnectionString"

connectionStringName="DefaultConnection"

Updated: Can you explicitly set your application name such as applicationName="WebTrends"? Then verify that you can create role and user using ASP.Net Configuraton.

enter image description here

于 2012-10-31T19:43:09.753 回答
1

1: Are you getting any errors or just invalid login?

2: Add in the providers section of both Membership and Roles:

 <membership defaultProvider="DefaultMembershipProvider">
  <providers>
    <clear/>
    ......
  </providers>
</membership>

3: Make sure you have set the defaultProvider for both Membership and Roles.

4: After making above changes, create a brand new user and try login.

5: EDIT: Make sure you don't have an empty structure for Login Authenticate event.

于 2012-10-31T21:39:38.933 回答
0

Login控件是在 ASP.NET 2.0 中添加的,默认情况下使用成员资格提供程序:

The Login control uses a membership provider to obtain user credentials. Unless you specify otherwise, the Login control uses the default membership provider defined in the Web.config file. To specify a different provider, set the MembershipProvider property to one of the membership provider names defined in your application's Web.config file. For more information, see Membership Providers.

If you want to use a custom authentication service, you can use the OnAuthenticate method to call the service.

If you've already set up the membership provider, you should be able to simply add a Login control to the page; you won't need any code to validate the login.

于 2012-10-31T18:46:37.203 回答