Tuesday, September 29, 2009

Configure ASP.NET Membership Provider and Role Provider to Use own SQL Server Database

First create a data base using SQL Server. (You can use Visual Studio to create your database)

image

image

Type your new database name and press ok to continue. Then it will prompt dialog for creating a new database.

Then press ok , Now you created a database in your SQL Server.

After that go to Visual Studio Command prompt

Program Files—> Visual Studio 2008 command prompt

and type aspnet_regsql.exe 

or

C:\Windows\Microsoft.NET\Framework\v2.oxx and run Aspnet_regsql.exe.

This command will launch wizard which can use to generate relevant database structure to selected database.

image image
image image

Now we have to configure the web.config

<connectionStrings>
<
add name="ConnectionString"
connectionString="Data Source=TestDB;Initial Catalog=Login;User ID=sa;Password=sapassword"/>
</
connectionStrings>
 <system.web>
<
roleManager enabled="true" defaultProvider="SqlRoleProvider">
<
providers>
<
clear/>
<
add name="SqlRoleProvider"
connectionStringName="ConnectionString"
type="System.Web.Security.SqlRoleProvider"/>
</
providers>
</
roleManager>

<
membership defaultProvider="SqlProvider"
userIsOnlineTimeWindow="15">
<
providers>
<
clear />
<
add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ConnectionString"
applicationName="MyApplication"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
passwordFormat="Hashed" />
</
providers>
</
membership>
</
system.web>

There can be other tags in between System.web tag.
Post a Comment