ASP. Membership role and Rights Management (i)

Source: Internet
Author: User

ASP. Membership Role and Rights Management (i)

This article directory:
1.membership Introduction
2.membership settings in SQL Server
3. Configure the Web. config
4. Create a user CreateUserWizard control
5. User logon Login Control
6. Display the name of the current user LoginName control
7. LoginStatus control that detects the user's authentication status
8. LoginView controls that present different content for different categories of users
9. Change the password of the ChangePassword control
10. PasswordRecovery Control for self-recovery password
11. Summary

1.membership Introduction

Membership, really interesting, very convenient, very useful. Introduced to everyone.

In an ASP. NET application, the membership class is used to validate user credentials and manage user settings, such as passwords and e-mail addresses. The membership class can be used alone or with FormsAuthentication to create a complete user authentication system for a Web application or Web site. The Login control encapsulates the membership class, providing a convenient user authentication mechanism.

The Membership class provides functionality that can be used to:
1) Create a new user.
2) Store membership information (user name, password, e-mail address, and support data) in Microsoft SQL Server or other similar data stores.
3) Authenticate the user who is accessing the site. Users can be authenticated programmatically, or you can use the Login control to create a complete authentication system that requires little or no code.
4) Manage Passwords. This includes creating, changing, retrieving, and resetting passwords, and more. You can choose to configure ASP. NET membership to require a password question and its answer to authenticate the password reset and retrieval requests of the user who has forgotten the password.
By default, ASP. NET membership can support all ASP. The default membership provider is SqlMembershipProvider and is specified in the Computer configuration by name AspNetSqlProvider. The default instance of SqlMembershipProvider is configured to connect to a local instance of Microsoft SQL Server.

2.membership settings in SQL Server

To use membership, you need to make some settings for the database, and friends who have used membership know that there are some inherent tables, views, and stored procedures in the database that are not in our own tables. However, we can create them through a wizard, which is aspnet_regsql.exe, which is generally located at: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 (mine is here)

It can either create options in the database or remove these settings.

Before running this program, I set up an empty database in SQL server2005: Membershipdemo. After establishing Membershipdemo, we run Aspnet_regsql.exe and specify membership as Membershipdemo.

3. Configure the Web. config

The Web. config is also to be modified. Add the authentication node under the system.web node.

Membership since it is used for membership management, of course, login authentication is required, so first add a forms validation.

1 <authentication mode= "Forms" >
2 <forms loginurl= "Login.aspx" name= ". Aspxlogin"/>
3 </authentication>

Also add membership nodes under the system.web node.

1 <membership defaultprovider= "AspNetSqlMembershipProvider" userisonlinetimewindow= "hashAlgorithmType=" " >
2 <providers>
3 <clear/>
4 <add connectionstringname= "ConnectionString" enablepasswordretrieval= "false" enablepasswordreset= "true" Requiresquestionandanswer= "true" applicationname= "/" requiresuniqueemail= "false" passwordformat= "Hashed" maxinvalidpasswordattempts= "5" minrequiredpasswordlength= "7" minrequirednonalphanumericcharacters= "1" passwordattemptwindow= "passwordstrengthregularexpression=" "Name=" AspNetSqlMembershipProvider "type=" System.Web.Security.SqlMembershipProvider, system.web, version=2.0.0.0, Culture=neutral, publickeytoken= b03f5f7f11d50a3a "/>
5 </providers>
6 </membership>

Property Explanation Description:

defaultprovider: The name of the provider. The default is AspNetSqlMembershipProvider. If you have more than one provider, it's wise to specify a default value
Userisonlinetimewindow: Specifies the number of minutes that a user is considered online after the date/time stamp of the most recent activity.
Hashalgorithmtype: The identifier of the algorithm used to hash the password, or null to use the default hashing algorithm.connectionStringName: The connection name of the membership database.
enablePasswordRetrieval: Indicates whether the current membership provider is configured to allow users to retrieve their passwords.
enablePasswordReset: Indicates whether the current membership provider is configured to allow users to reset their passwords.
requiresQuestionAndAnswer: Indicates whether the default membership provider requires users to answer a password question when password reset and retrieval occurs.
ApplicationName: The name of the application.
requiresUniqueEmail: Indicates whether the membership provider is configured to require a unique e-mail address for each user name.
Passwordformat: Indicates the format in which the password is stored in the membership data store. The values are optional clear, Encrypted, and Hashed. The clear password is stored in clear text, which improves the performance of storing and retrieving passwords, but is less secure and can be easily read when data source security is compromised. The Encrypted password is encrypted when it is stored and can be decrypted when the password is compared or retrieved. Such passwords require additional processing when stored and retrieved, but are more secure and are not easily accessible when the security of the data source is compromised. The Hashed password is hashed using a one-way hashing algorithm and a randomly generated salt value when it is stored in the database. When a password is validated, the password is hashed for validation with a salt value in the database. The hash password could not be retrieved.
maxinvalidpasswordattempts: The number of invalid password or invalid password answer attempts that were allowed before the membership user was locked out.
minRequiredPasswordLength: The minimum length required by the password.
minRequiredNonalphanumericCharacters: The minimum number of special characters that must be included in a valid password.
passwordAttemptWindow: The number of minutes that the maximum number of invalid or invalid password answer attempts is allowed before the membership user is locked out. This is an extra measure to prevent an unknown source from repeatedly trying to guess the answer to a password or password question for a membership user.
passwordstrengthregularexpression: The regular expression that calculates the password.

After you configure Web. config for membership, then configure its role management rolemanager, also under system.web.

1 <rolemanager enabled= "true" cacherolesincookie= "true" >
2 <providers>
3 <clear/>
4 <add connectionstringname= "ConnectionString" applicationname= "/" Name= "AspNetSqlRoleProvider" type= " System.Web.Security.SqlRoleProvider, system.web, version=2.0.0.0, Culture=neutral, publickeytoken=b03f5f7f11d50a3a "/>
5 </providers>
6 </roleManager>

Property Explanation Description:
cacheRolesInCookie: Indicates whether the role of the current user is cached in a Cookie.
When the cacheRolesInCookie property is set to True in the configuration file, the role information for each user is stored in a Cookie on the client. When a role management check determines whether a user belongs to a particular role, the role Cookie is checked before the calling role provider checks the list of roles in the data source. The Cookie is dynamically updated on the client to cache the most recently verified role name.
The Web. config is almost configured.


Really step into the chase.

4. Create a user CreateUserWizard control

Create an ASPX page in vs2005, named Createuserwizard.aspx. Drag a CreateUserWizard control directly from the Toolbox and set the Finishdestinationpageurl property, which indicates that the user clicks "Continue" to orient the page after it has been created.

1 <asp:createuserwizard id= "CreateUserWizard1" runat= "Server" continuedestinationpageurl= "~/default.aspx" >
2 </asp:CreateUserWizard>

ASP. Membership role and Rights Management (i)

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.