Membership Learning (2) Introduction to membership

Source: Internet
Author: User
Tags email account

Membership Learning (2) Introduction to membership

-- Do not write a line of code to implement the user authentication management system in asp.net

In this article, we will implement a simple website that provides functions such as user authentication, User Creation, password modification, and restriction of anonymous users to access some directories, the most amazing thing is to use asp. net2.0 implementation we almost do not need to manually write a line of code. -- I don't know what the programmer will do in the future :(!!

 

We create a web application from scratch and learn some of the technologies. The tasks to be completed by this application include:

1. Create a web application that contains the membership service and a user

2. Use the login control to obtain the user's creden and display the login user information.

3. Create a page in the directory on the website. Only login users can access the page.

4. Allow the website to create new users

5. Users can modify and reset

My development environment is windows2003, iis6.0, vs2005 team suit English, SQL server2005 express

 

Start of work

1. Create a website on local IIS

1. Open visual studio, file menu, and select New web site

2. select asp.net web site, select http in the location drop-down box, click the browser button, select local IIS in the pop-up box, open the Local Web Server, and select the default web site ), clickCreate New Web ApplicationIcon and name it membership. Click the open button to close the dialog box.

3. Select a working language (c #, etc.). You can select a different language when creating other web pages later :)

4. Click OK.

After a website is created, a default. aspx page is generated by default. We can keep it, or delete it and create a new page.

Ii. Configure membership

1. Create a new folder and name it MemberPages on the website.

2. Create a membeship user

A. Select Asp.net configuration in the menu website, select the Security tab in the open webpage, and clickUse the security Setup Wizard to configure security step by stepLink.

B. SelectFrom the InternetThe reason for using Form authentication is described in the Introduction to membership.

C. Click Next or use SQL server2005 express by default.App_DataDirectory to generate database files.

D. Click Next. Do not selectEnable roles for this web site

E. Click Next to create a User and enter the User Name, Password, and e-mail,SEcurity Question and Security Answer: create a user. Here, by the way, the default password settings for membership are strict and require letters, numbers, and special characters. in config, specify a regular expression for the membership password to modify the password rule. For details, refer to msdn.

3. Create a rule to restrict access to a specified directory

A. Go to the wizard and click next To Go To The create access Rule Page. In the displayed website directory box, expand the Directory and select the MemberPages folder we just created.

B.Rule appliesSelectAnonymous users,InPermissionSelect deny, which limits the permission of anonymous users to access the directory.

C. Click add this rule to create the permission, followed by Finish.

3. Configure an email for the Application

This operation aims to send the password to the user when the password is restored.

Select the Application tab page on the asp.net configuration page, and clickConfigure SMTP e-mail settings. Link. Configure an smtp server and an email account.

After configuring email, you can close this configuration page.

Iv. User Logon

Open the default. aspx page, use the design view, write a welcome or something on it, and drag the loginstatus control in the login control group. Create a login. aspx page. In this example, the page name must be login. aspx. By default, when an anonymous user accesses a restricted page, it is automatically transferred to login. aspx. The default settings can be changed through configuration. Here we use the default settings.

On the login. aspx page, drag and drop a login control group and placeValidationSummaryControl, used for actual error information, set the ValidationGroup attribute of ValidationSummary to the id name of the login control.

 

Display logon user information

Drag the default. aspx page to a loginview control, use the loginview smart tag, and select a template.AnonymousTemplate, Write "You have not logged on, click the login link to log on", and then select the TemplateLoggedInTemplate, Write the "welcome" character, and drag a loginname control behind it.

After that, you can first test your page and use the user we created above to log on to the page to see the different display.

5. Create a page that can only be accessed by users

Create a Members. aspx page in the created MemberPages folder, write welcome member, drag a HyperLInk control on the default. aspx page, and write ~ In the NavigateUrl attribute ~ /MemberPages/Members. aspx

You can also perform a test here.

6. Create a new user

Create a register. aspx in the root directory, drag and drop a CreateUserWizard control on the page, and set its ContinueDestinationPageUrl attribute ~ /Default. aspx. This attribute is the page to jump to after you click Finish. Add a Hyperlink control on the page and set NavigateUrl ~ /Default. aspx. Add a link to the register. aspx page on the default. aspx page. Put this link in the AnonymousTemplate template of the loginview control for a better look.

Test

7. Change the password

Create a ChangePassword. aspx file in the MemberPages folder, drag the ChangePassword control, and set its ContinueDestinationPageUrl attribute ~ /Default. aspx. Add a link to the changepassword. aspx page on the default. aspx page. We will put this link in the LoggedInTemplate template of the loginview control.

Test

8. Reset the password

Create a recoverypassword in the root directory. the aspx file, drag a passwordrecovery control, and place a link pointing to default. aspx. and then in default. add a link to the recoverypassword control in the AnonymousTemplate template of the loginview control of aspx.

Test

 

In this case, we can see that we did not write a line of code. :)

Post from: http://www.cnblogs.com/dotLive

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.