SIGN UP MEMBER LOGIN:    
ARTICLE

How to Configure ASP.NET Membership Using SQLMembershipProvider

Posted by Deepak Sharma Articles | ASP.NET Programming February 05, 2012
In this article, we will learn to configure ASP.NET Membership using SQLMembershipProvider.
Reader Level:

Introduction

The objective of this article is to configure ASP.NET Membership to store user information in an external SQL Server database. We will use SQLMembershipProvider for this task.

ASP.NET Membership

ASP.NET Membership enables us to validate and store user information. It creates all the necessary tables and stored procedures to store and manage user credentials. It provides an API that can be used to manage user's information programmatically.

ASP.NET Membership provides two types of Membership providers:

  1. SQLMembershipProvider : It is used to store user information in a SQL Server database
  2. ActiveDirectoryMembershipProvider : It is used to store user information in an Active Directory.

To configure SQLMembershipProvider, first you need to configure your database.

Open Visual Studio Command Prompt (All Programs -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt)

Type command : aspnet_regsql and press Enter

This will launch ASP.NET SQL Server Setup Wizard

asp.netmembersgip1.gif

Click Next

Leave the default selection "Configure SQL Server for application services" and click Next again.

Enter the server name, Select SQL Server authentication and enter user id and password as in the following figure. Select the database you want to configure. Here, I am using Employee database.

Click Next

asp.netmembersgip2.gif

Click Next and then Finish.

Now, you can see the new tables created in the Employee database for storing user credentials. These table names start with "aspnet_". Similarly, you can also see new Stored Procedures created in the database with "aspnet_" prefix.

asp.netmembersgip3.gif

Now, we have configured our Employee database. Our next task is to enable SQLMembershipProvider in a Web application. Follow these steps to do that:

  • Create a new ASP.NET Web Application
  • Add <authentication mode="Forms"/> in the Web.Config file. ASP.NET Membership works with only Forms Authentication
  • Add the following to enable SQLMembershipProvider:

              <membership defaultProvider="MyMembershipProvider" >
                <providers>
                  <
    add name="MyMembershipProvider"

              type="System.Web.Security.SqlMembershipProvider"
              connectionStringName="ConString" />
     </providers>
    </membership>
     

  • Add a connection string with the name "ConString" to connect with the Employee database

            <connectionStrings>
              <
    add name="SqlConString" connectionString="Data Source=localhost\SQL2005EXPRESS; User ID=youruserid; Password=yourpassword;
                   
    Initial Catalog=Employee;" />
            </connectionStrings>

Now, we are ready to use ASP.NET Membership to create a new user using CreateUserWizard control and authenticate users using Login control.

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks!!!

Posted by Deepak Sharma Feb 07, 2012

Great stuff.Keep it up!!!

Posted by Akash Ahlawat Feb 06, 2012

Really thanks for this useful article

Posted by Arjun Panwar Feb 06, 2012

Good article. Thanks for sharing.

Posted by Alok Pandey Feb 05, 2012

Great what an article. I will surely implement this.

Posted by Daisy Krause Feb 05, 2012
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor