Introduction to custom membershipprovider.

Source: Internet
Author: User

Namespace: system. Web. Security;

Membership is a static class built in vs DOTNET 2005. It is used for member Qualification Verification and operations.
It does not provide direct data operations, but is done by its provider.

// Membership class
// (From within. NET Framework 2.0Code)
Private Static membershipprovider s_provider;

Here we can see that membership defines a local static object s_provider, which is of the membershipprovider type.

To enable membership provisionProgramYou must create a class that inherits the abstract class of membershipprovider.
The attributes and methods required for the implementation of the membershipprovider abstract class, and descriptions of each attribute and method are provided.

// This is a piece of information in the machine. config configuration file.

<Membership>
<Providers>
<Add name = "aspnetsqlmembershipprovider"
Type = "system. Web. Security. sqlmembershipprovider,
System. Web,
Version = 2.0.0.0,
Culture = neutral,
Publickeytoken = b03f5f7f11d50a3a"
Connectionstringname = "localsqlserver"
Enablepasswordretrieval = "false"
Enablepasswordreset = "true"
Requiresquestionandanswer = "true"
Applicationname = "/"
Requiresuniqueemail = "false"
Passwordformat = "hashed"
Maxinvalidpasswordattempts = "5"
Minrequiredpasswordlength = "7"
Minrequirednonalphanumericcharacters = "1"
Passwordattemptwindow = "10"
Passwordstrengthregularexpression = ""/>
</Providers>
</Membership>

It indicates that the sqlmembershipprovider class is called as the s_provider object in membership.
Because membership will read this configuration information during initialize () and instantiate it.

// Code in the initialize () method
// (From the internal code of. NET Framework 2.0)
Membership. s_provider = membership. s_providers [section1.defaprovider provider];

S_providers is all instances in the <providers> section of all configuration files.
Section1.defaprovider provider is the defaultprovider attribute value of <membership>,
If it is not defined, use the internal default value aspnetsqlmembershipprovider, which is defined by the feature.

// Defaultprovider definition in the membershipsection class
// (From the internal code of. NET Framework 2.0)
[Configurationproperty ("defaultprovider ",
Defaultvalue = "aspnetsqlmembershipprovider "),
Stringvalidator (minlength = 1)]
Public String defaultprovider

So far, will you understand it?

// Sqlmembershipprovider Definition
// (From the internal code of. NET Framework 2.0)
Public class sqlmembershipprovider: membershipprovider

From this we can see that sqlmembershipprovider inherits the membershipprovider class.

If the following section is defined in Web. config in our system:

<Membership defaultprovider = "myprovider" userisonlinetimewindow = "15">
<Providers>
<Add
Name = "myprovider"
Type = "EOS. Web. Security. membershipeosprovider"
Connectionstringname = "localsqlserver"
Enablepasswordretrieval = "true"
Enablepasswordreset = "true"
Requiresquestionandanswer = "true"
Writeexceptionstoeventlog = "true"/>
</Providers>
</Membership>

// Sqlmembershipprovider Definition
// (From the internal code of. NET Framework 2.0)
Public sealed class membershipeosprovider: membershipprovider

note that defaultprovider = "myprovider" is defined here to indicate that membership defaults myprovider to s_provider object.
while myprovider is the EOS. Web. Security. membershipeosprovider class. It also inherits the membershipprovider class.

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.