views:

100

answers:

3

What is the MembershipProvider really used for? Do I need it at all? While using forms authentication I never specified any membership provider in the config file, i've been authenticating users by calling FormsAuthentication.SetAuthCookie. I've been reading quite a lot about it yesterday and I can't figure out why would i use it?

+3  A: 

The MembershipProvider is first of all a pluggable, standardised repository. If you base your authentication on MembershipProvider, you can later exchange it with another provider with no changes to your web site. Also, it is supported by standard components (the Login, LoginView, LoginStatus, LoginName and PasswordRecovery controls), and can be administered through the ASP.NET administration pages.

Tor Haugen
but do i HAVE to use it? or can i authenticate my users successfully without even knowing whar membershipprovider is?
agnieszka
Of course you don't have to. It's there for your convenience. All you need to do forms authentication is some code to check the username/password and call the FormsAuthentication methods.
Tor Haugen
+3  A: 

It is a very handy thing as Tor already said.

If you use the default controls for usermanagement/login/password reset etc, then you can just change a web.config setting, and your users are able to use another mechanisem to authenticate.

There are providers for AD, for SQL Server for ADAM, for Federrated Login and some more. It is not that important when you develop an intranet application, since you will most likely rely on NTLM or kerberos, but when you publish to the web it gets quite handy.

There is also a 2nd component to this provider, the roleprovider, which is another repository that can be used to handle roles in your application

Heiko Hatzfeld
+2  A: 

I don't think its that useful if you don't use the built in controls.

What you can do is just implement a membership provider with all methods throwing NotImplementedException, and implement as you find out what methods are actually used. Its just 2 or 3 if i remember correctly.

The RoleProvider is more useful, i use a provider with just the GetRolesForUser method implemented, so i can use the built in support for role-based authorization.

AndreasN
Yes, the controls help, but I think its usefull since it also stores the passwords hashed and provides methods for resetting the passwords etc
Heiko Hatzfeld