Click here to Skip to main content
15,867,906 members
Articles / Programming Languages / SQL

Using SQL Membership with ASP.NET Application

Rate me:
Please Sign up or sign in to vote.
4.46/5 (10 votes)
21 Jun 2010CPOL3 min read 92.4K   2.1K   30   10
How to setup SQL Membership with ASP.NET

Introduction

Most ASP.NET projects implement features like Login, Security, Password encryption, User Roles, Access rights, etc. Lot of code and logic goes into implementing all of this stuff. SQL Membership resolves all these concerns just by a few clicks and configurations and above all (which I like the most) without a single line of code. :)

Background

In this article, I will provide a complete walkthrough about using SQL Membership in ASP.NET projects. I hope you find this stuff beneficial.

Using the Code

SQL Membership is a wonderful way of interaction between ASP.NET and SQL Server. SQL Membership provides 2 kinds of Authentication methods:

  1. Using SQL Server Membership database (Kind of Form Authentication)
  2. Using Local System authentication (Windows Authentication)

The process is relatively easy to implement. I will go step by step to show the implementation. Let's consider that you are going to develop an application from scratch, so here we go:

  1. First, we need to setup the SQL Membership database. In order to create that database, please follow the steps:
    1. Go to Windows Start menu>>All Programs>>Microsoft Visual Studio 2005/2008>>Visual Studio Tools and click Visual Studio 2008 Command Prompt
    2. Type aspnet_regsql and press Enter key from the keyboard.

      1.png

    3. This will launch SQL Membership Wizard as follows. Click Next button to continue.

      2.png

    4. On the next screen select the first option to "Configure SQL Server for application services". Click Next to continue.

      3.png

    5. This screen is important as you will mention the Database information here. On the basis of that, table structures and other things will be created. You can use an existing database or create a new one.

      4.png

    6. After filling all the information click next and Finish. :) You guessed right, your SQL Membership database is ready now.
  2. Now let's connect our ASP.NET Website application to this database. For this, first create an ASP.NET website in Visual Studio 2005/2008.
  3. Now open the Web.Config file for the project and add a well qualified Connection String for the SQL Server Membership database you are going to use.
    XML
    <connectionstrings>
        <add name="abcdCS" connectionstring="
        Data Source=myserver\sqlexpress;Initial Catalog=abcd;
        User ID=sa;Password=pass" 
        providername="System.Data.SqlClient" />
    </connectionstrings>

    This Connection String will be used by the ASP.NET Configuration for connection with the database.

  4. After that, click on VS 2005/2008 Project menu>>ASP.NET Configuration

    5.png

  5. This will launch the ASP.NET Web Site Administration Tool. Here, you will test the database connection, manage users, roles, permissions, etc.
  6. First click on the Provider tab.

    6.png

    Here you will be testing the database connection. Click on both the links one by one to test the connectivity with database.

  7. Clicking the above links will show screen as mentioned below:

    7.png

    9.png

    Click the "Test" link in each screen to check the connection status.

  8. If your connection is successful, you will get a screen like this:

    8.png

So far so good. :) We are done with the connection part of SQL Membership database with the ASP.NET website application.

Now in order to select authentication types, create users, manage roles, and access rules, you need to see the Security tab.

10.png

In order to setup the SMTP settings, Application Settings, Debugging and Tracing settings, and default error page, you need to visit the Application tab.

By now, you have seen that we have not written even a single line of code. Now for authentication, you can use the Login Control from the Visual Studio 2005/2008 toolbox. You just need to put that control on your webpage and set its DestinationPageUrl. That's it. You don't need to worry about codes, validations, etc. It will do it all for you. Interesting haa........ :)

History

  • 22nd June, 2011: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
United States United States
I am a developer in Microsoft Technologies like .NET, SharePoint etc.

Comments and Discussions

 
QuestionDecription of Aspnet_membership password Pin
sekharnani6-Jan-13 23:12
sekharnani6-Jan-13 23:12 
AnswerRe: Decription of Aspnet_membership password Pin
cwilliam9-Jul-15 15:35
cwilliam9-Jul-15 15:35 
GeneralMy vote of 4 Pin
AndrewFellGordon29-Jun-10 7:36
AndrewFellGordon29-Jun-10 7:36 
GeneralMy vote of 2 Pin
sfadhel29-Jun-10 5:36
sfadhel29-Jun-10 5:36 
GeneralHmmm Pin
KansasCoder28-Jun-10 15:57
KansasCoder28-Jun-10 15:57 
GeneralI didn't even bother to rate this... Pin
cwilliam28-Jun-10 13:16
cwilliam28-Jun-10 13:16 
SuggestionRe: I didn't even bother to rate this... Pin
VBdotnetSara24-Jul-11 17:46
VBdotnetSara24-Jul-11 17:46 
GeneralRe: I didn't even bother to rate this... Pin
Suraj856-Aug-12 22:44
Suraj856-Aug-12 22:44 
GeneralMore details would add value Pin
rashidkhan9867621-Jun-10 23:56
rashidkhan9867621-Jun-10 23:56 
GeneralRe: More details would add value Pin
Wild-Programmer22-Jun-10 0:11
Wild-Programmer22-Jun-10 0:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.