Analysis of ASP. NET Membership

Source: Internet
Author: User

Membership, Roles, or Profile features are used to develop an ASP. NET2.0 application locally. You have created some new ASP. NET users, and everything is fine.

Copy the program to the remote server) or just move it to another directory on your local server) and run the program. For some reason, although we can connect to the Membership database, an error will occur when we log in. It does not throw a connection error), but prompts you with a similar error: "failed to log on. please try again" Login attempt unsuccessful, please try again)

Cause:
This common error occurs because Membership, roles, and profile providers have been added to the web. config of the program. However, applicationName attribute is not specified. Suppose that the bold Section of the following code exists)

 
 
  1. <membership> 
  2. <providers> 
  3. <clear/> 
  4. <add name="AspNetSqlMembershipProvider" 
  5. type="System.Web.Security.SqlMembershipProvider, System.Web, 
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
  6. connectionStringName="LocalSqlServer" 
  7. enablePasswordRetrieval="false" 
  8. enablePasswordReset="true" 
  9. requiresQuestionAndAnswer="true" 
  10. requiresUniqueEmail="false" 
  11. passwordFormat="Hashed" 
  12. maxInvalidPasswordAttempts="5" 
  13. minRequiredPasswordLength="7" 
  14. minRequiredNonalphanumericCharacters="1" 
  15. passwordAttemptWindow="10" 
  16. passwordStrengthRegularExpression="" 
  17. applicationName="/" 
  18. /> 
  19. </providers> 
  20. </membership> 

If it is copied to another place or server and replaced with a virtual path such as "/app1" or, when Membership APIs is used, they "cannot see" existing users in the database-because they will use a different applicationName to search for users in the database, filter users in the application_Users table accordingly. This is why the above error occurs.

How to solve this problem:
The simplest way is to open the aspnet_Users and aspnet_Application tables in the ASPNETDB database and "Recall" figure out, because we may have forgotten the name of our virtual directory at that time) the program name used to create users and other data is searched in the aspnet_Application table)

Then open your web. in the config file, add an applicationName attribute to the place where the provider declares and assign values to it. For example, the following code sets it to/website8 in the aspnet_Application table:

 
 
  1. <membership> 
  2. <providers> 
  3. <clear/> 
  4. <add name="AspNetSqlMembershipProvider" 
  5. type="System.Web.Security.SqlMembershipProvider, System.Web, 
    Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
  6. connectionStringName="LocalSqlServer" 
  7. enablePasswordRetrieval="false" 
  8. enablePasswordReset="true" 
  9. requiresQuestionAndAnswer="true" 
  10. requiresUniqueEmail="false" 
  11. passwordFormat="Hashed" 
  12. maxInvalidPasswordAttempts="5" 
  13. minRequiredPasswordLength="7" 
  14. minRequiredNonalphanumericCharacters="1" 
  15. passwordAttemptWindow="10" 
  16. passwordStrengthRegularExpression="" 
  17. applicationName="/website8" 
  18. /> 
  19. </providers> 
  20. </membership> 

The above describes ASP. NET's Membership

  1. ASP. NET TypeConverter
  2. Analysis on TypeResolver of ASP. NET
  3. Define JavaScriptConverter in ASP. NET
  4. How to replace Sys. Services in ASP. NET
  5. Use Profile Service of ASP. NET AJAX

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.