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
- < connectionStrings>
- < add name="SqlServices" connectionString="Data Source=Archer;Integrated Security=SSPI;Initial Catalog=MembershipDemo;" />
- < remove name="LocalSqlServer"/>
- < /connectionStrings>
B. login authentication is required, and a form authentication is added.
- < authentication mode="Forms">
- < forms loginUrl="login.aspx" name=".aspxlogin"/>
- < /authentication>
C. membership configuration: Add a membership Node
- < membership defaultProvider="AspNetMembershipProvider" userIsOnlineTimeWindow="20">
- < providers>
- < remove name="AspNetSqlMembershipProvider" />
- < add name="AspNetMembershipProvider"
- type="System.Web.Security.SqlMembershipProvider"
- connectionStringName="SqlServices"
- enablePasswordRetrieval="true"
- enablePasswordReset="true"
- requiresQuestionAndAnswer="true"
- passwordFormat="Clear"
- applicationName="/" />
- < /providers>
- < /membership>
D. configure its role management roleManager.
- < roleManager enabled="true" defaultProvider ="AspNetRoleProvider">
- < providers>
- < remove name="AspNetSqlRoleProvider" />
- < add name="AspNetRoleProvider" connectionStringName="SqlServices"
- type="System.Web.Security.SqlRoleProvider,System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
- applicationName="/" />
- < /providers>
- < /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
- < mailSettings>
- < smtp deliveryMethod="Network" from="Admin@coplay.com">
- < network defaultCredentials="false" host="smtp.coplay.com" password="*" port="25" userName=*@coplay.com />
- < /smtp>
- < /mailSettings>
This completes the membership configuration of the ASP. NET login control.