How to configure the ASP. NET Logon control membership (zhuan)

Source: Internet
Author: User
Tags connectionstrings

This article is intended for developers who have used ASP. NET login controls. The ASP. NET Logon control requires membership configuration. You only need to add a database and modify the configuration file. The following are the implementation steps:

1. An empty database is created in SQL server2005: membershipdemo

2. Run aspnet_regsql.exe in the C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727directory to automatically create table structures and stored procedures.

3. Configure web. config

A. Add a database connection string

 
 
  1. < connectionStrings>
  2.     < add name="SqlServices" connectionString="Data Source=Archer;Integrated Security=SSPI;Initial Catalog=MembershipDemo;" />
  3.     < remove name="LocalSqlServer"/>
  4. < /connectionStrings>

B. login authentication is required, and a form authentication is added.

 
 
  1. < authentication mode="Forms">  
  2. < forms loginUrl="login.aspx" name=".aspxlogin"/>  
  3. < /authentication> 

C. membership configuration: Add a membership Node

 
 
  1. < membership defaultProvider="AspNetMembershipProvider" userIsOnlineTimeWindow="20"> 
  2.         < providers> 
  3.           < remove name="AspNetSqlMembershipProvider" /> 
  4.           < add name="AspNetMembershipProvider"
  5.               type="System.Web.Security.SqlMembershipProvider"
  6.               connectionStringName="SqlServices"
  7.               enablePasswordRetrieval="true"
  8.               enablePasswordReset="true"
  9.               requiresQuestionAndAnswer="true"
  10.               passwordFormat="Clear"
  11.               applicationName="/" /> 
  12.         < /providers> 
  13.       < /membership> 

D. configure its role management roleManager.

 
 
  1. < roleManager enabled="true" defaultProvider ="AspNetRoleProvider"> 
  2.         < providers> 
  3.           < remove name="AspNetSqlRoleProvider" /> 
  4.           < add name="AspNetRoleProvider" connectionStringName="SqlServices"  
  5.                type="System.Web.Security.SqlRoleProvider,System.Web, Version=2.0.0.0, Culture=neutral,    PublicKeyToken=b03f5f7f11d50a3a"
  6.               applicationName="/" /> 
  7.         < /providers> 
  8.       < /roleManager> 

Note that the reason for removing the node above is that by default, the connection used is LocalSqlServer defined in machine. config. We can use our own connection to make it easier.

4. Create a web site, add the webpage NewUser. aspx, drag the CreateUserWizard control, and set its FinishDestinationPageUrl attribute to default. aspx.

5. The same applies to other ASP. NET login controls. You can drag them to use them.

6. If you want to use the password retrieval function, you need to configure the email server

 
 
  1. < mailSettings>  
  2. < smtp deliveryMethod="Network" from="Admin@coplay.com">  
  3. < network defaultCredentials="false" host="smtp.coplay.com" password="*" port="25" userName=*@coplay.com />  
  4. < /smtp>  
  5. < /mailSettings> 

This completes the membership configuration of the ASP. NET login control.

Related Article

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.