Step for customizing Asp.net 2.0 membership and entry 'aspnetsqlmembershipprovider' has already been added

Source: Internet
Author: User
Step for customizing Asp.net 2.0 membership and resolving the entry 'aspnetsqlmembershipprovider' has already been added Error

Today, the membership function is used in another new system. Although I have learned a lot about it a long time ago, I have suffered a lot from it.ProgramHas never been a chance to use it. Today, I used it in new programs. However, although Microsoft has considered a lot of rigorous configuration, it has brought us a lot of trouble. For example, the username and password must be the simplest type of naming, that is, PAS $ w0rd, which makes development and testing very troublesome for programmers, many users still hate this password registration method. I am a victim myself. I analyzed membership and looked at msdn. These restrictions are defined by ourselves. The following describes how to customize the methods and how to solve a nasty error.

1. first, go to c: \ windows \ Microsoft. net \ framework \ v2.0.50727 \ config find the machine. config File, find the following line of configuration (when you find it, it may all be written as a line, and you can press enter to change it to the following style for better reading)
<Membership>
<Providers>
<Add name = "aspnetsqlmembershipprovider"
Type = "system. Web. Security. sqlmembershipprovider"
Connectionstringname = "localsqlserver"
Enablepasswordretrieval = "false"
Enablepasswordreset = "true"
Requiresquestionandanswer = "true"
Applicationname = "/"
Requiresuniqueemail = "false"
Passwordformat = "hashed"
Maxinvalidpasswordattempts = "5"
Minrequiredpasswordlength = "7"
Minrequirednonalphanumericcharacters = "1"
Passwordattemptwindow = "10"
Passwordstrengthregularexpression = ""/>
</Providers>
</Membership>

2. After you get the membership configuration, the next step is to copy it to the <system. Web> module of your web. config. Here we need to explain a little bit,By default, Asp.net 2.0 calls the membership configuration of machine. config by default.That is why you need to copy the configuration to your own web. config, because you need to modify some numeric values.

3. Now, let's start cutting.

<Membership>
<Providers>
<Add name = "aspnetsqlmembershipprovider"
Type = "system. Web. Security. sqlmembershipprovider"
Connectionstringname = "localsqlserver"
Enablepasswordretrieval = "false"
Enablepasswordreset = "true"
Requiresquestionandanswer = "true"
Applicationname = "/"
Requiresuniqueemail = "false"
Passwordformat = "hashed"
Maxinvalidpasswordattempts = "5"
Minrequiredpasswordlength = "4"
Minrequirednonalphanumericcharacters = "0"
Passwordattemptwindow = "10"
Passwordstrengthregularexpression = ""/>
</Providers>
</Membership>

(I modified the red part.) It is almost done here, but don't be too happy because if you run it like this, an error will occur"The entry 'aspnetsqlmembershipprovider 'has already been added."If you see this, congratulations, because the answer you want is later. Because you are on the web. after rewriting the membership configuration in config, Asp.net still runs the machine first. the membership configuration in config will read your web. the Asp.net engine will be confused during config, because two membership configurations appear. This is why this error occurs.

Let's talk about it and solve the problem. In one sentence, both methods can be solved.
Before <Add name = "aspnetsqlmembershipprovider", add

<Remove name = "aspnetsqlmembershipprovider"/>

Or

<Clear/>

Okay, the problem is solved.

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.