views:

656

answers:

3

How do you create a MembershipProvider for use in an ASP.NET/MVC website?

Doesn't it generate the tables it needs for you in your database?

+1  A: 

Google is your friend:

The vast majority of it depends on what you want to do. Maybe if you expand on why you want to create a custom one we could give a better answer.

Mcbeev
@Mcbeev, perhaps I don't want a custom one, I simply want to use a MembershipProvider with an asp.net mvc application.
KingNestor
You did ask how you create one.
Chad Moran
stackoverflow is my bestest friend though :-)
Simon_Weaver
+1  A: 

Basically you have to make a class that inherits from the abstract MembershipProvider class in the .NET framework. Then you have to implement all of the abstract members of the base class. ValidateUser, GetUser and Initialize are probably the most important members to implement depending on how much of the interface you want to support.

The default membership provider doesn't create anything in the database automagically. You have to run the aspnet_regsql.exe to create the necessary databases.

To use the default asp.net SqlMembershipProvider. You just have to enable it and enter a proper connection string (see example configuration on MSDN). Then you have to create a login page that validates the user using the configured membership provider. The easiest way is to use the Login Control.

JohannesH
+4  A: 

Default template for ASP.NET/MVC already have Membership registered within your web.config. At the end you just need to run:

aspnet_regsql.exe -W

This command will start wizard that will guide you accross database creation process.

Mike Chaliy
Note: You should run that from a VS 2008 command prompt - it's highly likely that the default paths won't have the .NET framework folders mapped.
Zhaph - Ben Duguid
Yep,typically this command located at c:\Windows\Microsoft.NET\Framework\v2.0.50727\
Mike Chaliy