Use of the membershipuser and membership classes

Source: Internet
Author: User

MembershipuserClass usage (system. Web. Security must be referenced)

MembershipuserObjects are used to indicate a single qualified user in the data storage area. This object discloses information about qualified users (such as email addresses) and provides functions for qualified users (such as changing or resetting their passwords ).

MembershipuserObjects can be returned by the getuser and createuser methods, or as part of the membershipusercollection returned by the getallusers, findusersbyname, and findusersbyemail methods.

The updateuser method requiresMembershipuserObject.

Membershipuser Member

Publish and update information of qualified users in the data storage area.

The following table lists the members exposed by the membershipuser type.

Common Constructor

Name

Description

Membershipuser

Overloaded. Creates a new membership user object using the specified property value.

Protected Constructors

Name

Description

Membershipuser

Overloaded. Creates a new membership user object using the specified property value.

Public attributes

Name

Description

Comment

Obtains or sets application-specific information of qualified users.

Creationdate

Obtain the date and time when the user is added to the member qualification data storage area.

Email

Obtains or sets the email address of a user who is a member.

Isapproved

Gets or sets a value to indicate whether identity verification can be performed on qualified users.

Islockedout

Gets a value that indicates whether a member is locked and cannot be verified.

Isonline

Gets a value indicating whether the user is online.

Lastactivitydate

Gets or sets the date and time on which the user was last authenticated or accessed the application.

Lastlockoutdate

Obtain the date and time of the most recent locked member user.

Lastlogindate

Obtains or sets the date and time of the last authentication performed by the user.

Lastpasswordchangeddate

The date and time when the password of the last updated member is obtained.

Passwordquestion

An error occurred while listing the passwords of qualified users.

Providername

Obtain the name of the membership provider, which stores and retrieves user information of the member users.

Provideruserkey

Obtain the User Identifier from the user's membership data source. Corresponding to the userid in the database

Username

Obtain the login name of a user who is a member.

Common Methods

Name

Description

Changepassword

Update the password of a qualified user in the data storage area.

Changepasswordquestionandanswer

Update the password prompts and answers of qualified users in the data storage area.

Equals

Overloaded. Determine whether the two object instances are equal. (Inherit from object .)

Gethashcode

Used as a hash function of a specific type. Gethashcode is applicable to hash algorithms and data structures (such as hash tables. (Inherit from object .)

GetPassword

Overloaded. Obtain the password of a qualified user from the data storage area.

GetType

Obtain the type of the current instance. (Inherit from object .)

Referenceequals

Determine the specifiedObjectWhether the instance is the same. (Inherit from object .)

Resetpassword

Overloaded. Reset the user password to an automatically generated new password.

Tostring

Overwritten. Returns the username of the qualified user.

Unlockuser

Clear the user's lock status to verify the membership of the user.

 

Example 1 (how to obtain the userid value in the existing Member qualification information ):

Using system. Web. Security;

 

Membershipuser u = membership. getuser (httpcontext. Current. User. Identity. Name); // obtain the membership object based on the logged-on user on the current page.

If (u! = NULL) // determine whether the user has logged on

{

String currentuserid = U. provideruserkey. tostring (); // because the value of provideruserkey is of the guid type, you must use the tostring () method to obtain the string value.

String email = U. Email;

String passwordquestion = U. passwordquestion;

}

Example 2 (create a new user ):

Membershipcreatestatus status;

Protected void button#click (Object sender, eventargs E)

{

Membershipuser u = membership. createuser ("Test2", "Test2? Test2 "," test2@126.com "," who are you? "," Test222 ", true, out status );

 

If (u = NULL)

{

Response. Write ("failed to create user! ");

}

Else

{

Response. Write ("user created successfully! ");

}

}

Example 3: delete a user ):

Protected void button2_click (Object sender, eventargs E)

{

If (membership. deleteuser ("Test2", true ))

{

Response. Write ("User deleted! ");

}

Else

{

Response. Write ("failed to delete user! ");

}

}

Membership Member

Verify user creden。 and manage user settings. This class cannot be inherited.

The following table lists members exposed by the membership type.

Public attributes

 

Name

Description

Applicationname

Obtain or set the application name.

Enablepasswordreset

Obtain a value indicating whether the current membership provider is configured to allow users to reset their passwords.

Enablepasswordretrieval

Obtain a value indicating whether the current membership provider is configured to allow users to retrieve their passwords.

Hashalgorithmtype

The identifier of the algorithm used to hash the password.

Maxinvalidpasswordattempts

The number of attempts to receive questions and answers to the invalid or invalid passwords allowed before the user is authorized to be locked.

Minrequirednonalphanumericcharacters

Obtain the minimum number of special characters that a valid Password must contain.

Minrequiredpasswordlength

The minimum length required to obtain the password.

Passwordattemptwindow

Obtain the maximum number of minutes for which a question answer attempt is prompted for an invalid password or password that is allowed before the user is locked.

Passwordstrengthregularexpression

Obtain the regular expression used to calculate the password.

Provider

Gets a reference to the default membership provider for the application.

Providers

Obtains a set of membership providers for ASP. NET applications.

Requiresquestionandanswer

Obtain a value indicating whether the default membership provider requires the user to answer the password prompt during password reset and retrieval.

Userisonlinetimewindow

Specify the number of minutes that the user is considered to be online after the date/timestamp of the last activity.

Common Methods

 

Name

Description

Createuser

Overloaded. Add a new user to the data storage area.

Deleteuser

Overloaded. Delete a user from the database.

Equals

Overloaded. Determine whether the two object instances are equal. (Inherit from object .)

Findusersbyemail

Overloaded. Obtains a set of qualified users. The email address contains the specified email address to be matched.

Findusersbyname

Overloaded. Obtains a set of qualified users. The user name contains the specified user name to be matched.

Generatepassword

Generate a random password of the specified length.

Getallusers

Overloaded. Obtains a set of users in the database.

Gethashcode

Used as a hash function of a specific type. Gethashcode is applicable to hash algorithms and data structures (such as hash tables. (Inherit from object .)

Getnumberofusersonline

Obtain the number of users currently accessing the application.

GetType

Obtain the type of the current instance. (Inherit from object .)

Getuser

Overloaded. Obtain information of qualified users from the data source.

Getusernamebyemail

Obtain a user name. The user's email address matches the specified email address.

Referenceequals

Determine the specifiedObjectWhether the instance is the same. (Inherit from object .)

Tostring

Returns the currentObject. (Inherit from object .)

Updateuser

Update the database with the specified user information.

Validateuser

Verify that the provided user name and password are valid.

Protected Methods

 

Name

Description

Finalize

AllowObjectIn "Garbage Collection ",ObjectPreviously, I tried to release resources and perform other cleanup operations. (Inherit from object .)

Memberwiseclone

Create currentObject. (Inherit from object .)

Public Events

 

Name

Description

Validatingpassword

It occurs when a user is created, the password is changed, or the password is reset.

 

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.