4

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?

3 Answers 3

4

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.

2
  • 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. Feb 17, 2009 at 9:06
  • Yep,typically this command located at c:\Windows\Microsoft.NET\Framework\v2.0.50727\ Feb 17, 2009 at 9:29
2

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.

1

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.

3
  • @Mcbeev, perhaps I don't want a custom one, I simply want to use a MembershipProvider with an asp.net mvc application.
    – KingNestor
    Feb 17, 2009 at 0:56
  • You did ask how you create one.
    – Chad Moran
    Feb 17, 2009 at 4:25
  • 1
    stackoverflow is my bestest friend though :-) May 14, 2009 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.