[How Do I:] Create a Custom Membership Provider?

Please install Silverlight or click download to watch video locally.

A Membership Provider allows a web application to store and retrieve membership data for a user, and the standard ASP.NET Membership Provider uses pre-defined SQL Server tables. In this video we learn how to create a custom membership provider that uses custom SQL Server tables separate from the pre-defined tables used by the standard provider. The principles covered in the video will apply to creating custom membership providers using other databases such as Access or Oracle. After learning to create the custom membership provider, we learn how to configure the provider in a web application, and see a demonstration of creating a new user and authenticating the new user with the custom membership provider.

Presented by Chris Pels

Duration: 29 minutes, 3 seconds

Date: 05 October 2007

Watch    Video   |   Download    Video   |   VB Code    C# Code

Video downloads: WMV  |  Zune  |  iPod  |  PSP  |  MPEG-4  |  3GP

Audio downloads: AAC  |  WMA  |  MPEG-4  |  MPEG-3  |  MPEG-2

Comments : 36

Leave a Comment

Bibhabasu : On March 27, 2008 6:42 AM said:

I want to use the the CreateUserWizard control ,but i want to use my own database.How do i do that ?how do I create the custom membership provider?

kmj2384 : On April 08, 2008 8:30 PM said:

Can someone explain to me how to create the very first project that Chris starts working off of?  In my website, when I choose add new item and add class, I don't get all the files nested under what I created.  Therefore, I think I need to create that very first file but it's not explained how to do that.  Any help would be appreciated.  Thank you.

Soha.Jawabreh : On May 13, 2008 4:04 AM said:

Thank you Chris

An excellent video

soha

muhammed : On July 23, 2008 5:42 AM said:

good video thanks

cv_vikram : On August 08, 2008 4:59 PM said:

thanks...

Antikom : On August 15, 2008 4:34 AM said:

Chris thank you for this video!

Antikom.

Juwar : On August 30, 2008 6:33 PM said:

How can I create my own createuserwizard.  I don't want the security question/answer as part of the membership, nor do I want the email, I want just username, password and pass these values to the provider.

subhasisrout : On September 09, 2008 4:04 AM said:

UpdateFailureCount method is not updating anything....Could anyone please explain....

djibril_chimere_DIAW : On October 28, 2008 12:56 PM said:

Thanks ! Jërëjëf !

mongoose_za : On November 21, 2008 4:56 AM said:

I personally thought the video was not that good. I downloaded the sample project and followed along with the video and got connectionString exceptions thrown. COuldn't even get the project to run properly. It would have been much better if Chris took a method and perhaps changed it slighty, to show how to customize something. Because this was really just spectating something which is already there and although i can see it and follow along i'm not to sure how to customize it, which is what this video was supposed to show me. But thats just me...

rohit.kumar.barik : On December 08, 2008 1:28 AM said:

i canot dowload this video.The zip file is showing corrupted.Can u please help me

kenshinofkin : On December 17, 2008 2:37 AM said:

Awesome video! One problem though. Its easy to see what columns you use to create the database but not seeing the stored procedures or putting the code up is a downfall. Is there anyway we can get these stored procedures?

bohunt : On December 22, 2008 4:47 AM said:

I thought it was a great video, you should try to make a few videos about the actual coding.

rami_nassar : On December 25, 2008 11:11 AM said:

can you give us as example taturial on how to add additional information to membership provider??

phb7688 : On January 03, 2009 10:30 AM said:

Perfect walkthrough of how to use a custom or alternative data store for login to a web site in Visual Studio for someone at my "hobbyist" level.

Veerakondalu : On February 09, 2009 10:47 PM said:

Very good Video.

ai101 : On March 25, 2009 5:01 PM said:

Excellent video

Posted at 01:41 in the video

lucmi : On April 08, 2009 1:14 PM said:
Inizializzazione
Disco Patrick : On April 15, 2009 12:04 PM said:

Are we free to use your code examples in our own projects?

cleverwisdomforever : On April 16, 2009 1:31 AM said:

Thank you so much Chris Pells nice Video!!!

Burglar_Cat@yahoo.com : On April 29, 2009 3:58 AM said:

Hi, Programming Masters.

I come here to seek helps. I created a .aspx file with creatuserwizard control in order to insert my own member account. However my boss ask us that add all the items that need to be inserted in a page rather than steps. Some I modify table of CreateUserWizardStep1 with adding some tr,td and corresponding control such as zip textbox or statedropdownlist in. Then, I met my problem for the database. I add some new tables in order to store data, each table I set a column named useID which is a foreigner key PK with table aspnet_Membership. I need to insert rows with corresponding userID. However, the userID only created and then to be inserted into table aspnet_Membership when an account already be created, that means I can not use sql commands to get that UserID. So shall expriented enough to cope with this with .net?

I have my grateful thanks here.

Burglar_Cat@yahoo.com : On April 29, 2009 4:05 AM said:

Hi, Programming Masters.

I come here to seek helps. I created a .aspx file with creatuserwizard control in order to insert my own member account. However my boss ask us that add all the items that need to be inserted in a page rather than steps. Some I modify table of CreateUserWizardStep1 with adding some tr,td and corresponding control such as zip textbox or statedropdownlist in. Then, I met my problem for the database. I add some new tables in order to store data, each table I set a column named useID which is a foreigner key PK with table aspnet_Membership. I need to insert rows with corresponding userID. However, the userID only created and then to be inserted into table aspnet_Membership when an account already be created, that means I can not use sql commands to get that UserID. So shall expriented enough to cope with this with .net?

I have my grateful thanks here.

whitewolve : On April 29, 2009 11:17 PM said:

Hey Chris, great video man... I have used this technique on two of my projects thanks.

But I just got into a problem some few days ago and I have not been able to find a way around it. I am trying to reset a user password, and I get a "There is already an open DataReader associated with this Command which must be closed first" Can you throw some light here please? I do not have any idea what I am doing wrong. Plus is there a way I can decrypt the passwords? Please find below, my ResetPassword Code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Membership.EnablePasswordRetrieval Then

FormsAuthentication.RedirectToLoginPage()

End If

Msg.Text = ""

If Not IsPostBack Then

Msg.Text = "Please supply a username."

Else

VerifyUsername()

End If

End Sub

Public Sub VerifyUsername()

u = Membership.GetUser(UsernameTextBox.Text, False)

If u Is Nothing Then

Msg.Text = "Username " & UsernameTextBox.Text & " not found. Please check the value and re-enter."

QuestionLabel.Text = ""

QuestionLabel.Enabled = False

AnswerTextBox.Enabled = False

ResetPasswordButton.Enabled = False

Else

QuestionLabel.Text = u.PasswordQuestion

QuestionLabel.Enabled = True

AnswerTextBox.Enabled = True

ResetPasswordButton.Enabled = True

End If

End Sub

Protected Sub ResetPasswordButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ResetPasswordButton.Click

Dim newPassword As String

u = Membership.GetUser(UsernameTextBox.Text, False)

If u Is Nothing Then

Msg.Text = "Username " & UsernameTextBox.Text & " not found. Please check the value and re-enter."

Return

End If

Try

newPassword = u.ResetPassword(AnswerTextBox.Text)

Catch ex As MembershipPasswordException

Msg.Text = "Invalid password answer. Please re-enter and try again."

Return

Catch ex As Exception

Msg.Text = ex.Message

Return

End Try

If Not newPassword Is Nothing Then

Msg.Text = "Password reset. Your new password is: " & newPassword

Else

Msg.Text = "Password reset failed. Please re-enter your values and try again."

End If

End Sub

Puneri_25 : On April 30, 2009 6:34 AM said:

I've customized createuserwizard to add some more fileds. So how to add more arguments in createuser method?

noobie : On May 21, 2009 1:56 AM said:

you have to create an Overload Function of CreateUser Method.

shatru : On June 24, 2009 10:23 AM said:

Can anyone explain the process of this video. The file named HDIMembershipProvide.cs (HDIMembershipProvide.vb in video) didnt get created in my case.

I follow these steps:

First I created a blank solution

Then I add a project of class library in the solution.

Then I add the inheritence part t te class i.e.

System.Web.Security.MembershipProvider.

But when I looked into the Solution Explorer I didnt find the file.

Hope things are clear.

Thanx in advnce

jtutoff : On June 26, 2009 8:30 PM said:

Great!

hajan : On August 06, 2009 1:41 AM said:

Very nice video!

VanSud : On September 17, 2009 3:12 PM said:

Hello,

I have developed the CustomMembershipProvider and everything works fine.

But I am wondering how do we set the "IsOnline" field value when the user logs in & out?

Any suggessions on how to do this?

Thanks,

VanSud : On September 17, 2009 3:14 PM said:

Hello,

I have developed the CustomMembershipProvider and everything works fine.

But I am wondering how do we set the "IsOnline" field value when the user logs in & out?

Any suggessions on how to do this?

Thanks,

s.todorov : On October 11, 2009 6:57 PM said:

DUDE............................

The best!!!

Thanks a lot

mcgmatt : On October 26, 2009 6:11 PM said:

In the provided C# code, the Sql objects (SqlConnection, SqlCommand, SqlAdapater, SqlDataReader) are not declared in using() blocks, so they won't be disposed.

Also, in a couple of methods, you're missing totalRecords = counter; leaving totalRecords = 0.

Pak514 : On October 27, 2009 10:04 PM said:

Poor video and misleading title. There's nothing custom about this.

david hawk : On November 02, 2009 9:56 PM said:

The C# zip file has a bug. If built as-is, it will throw an exception at line 236 of HDIMembershipProvide.cs with an error message "Connection string cannot be blank."

This is due to a typo in the HDIMembershipProvide.cs file at line 229:

incorrect:

ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["HDIConnectionString"]];

should be:

ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];

Posted at 21:58 in the video

joshc1107 : On November 02, 2009 10:56 PM said:
How do you determine the type name?
induster : On November 07, 2009 8:20 PM said:

@ david hawk

The C# file typo has been corrected. Thanks for this video, it's given me a great head start.

Leave a Comment

You must be logged in to leave a comment. Click here to log in.

Microsoft Communities