Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SimpleMembership in MVC without Entity Framework

What are the required steps to use SimpleMembership (ASP.NET MVC 4) with RavenDB (or other databases) instead of SQL Server?

I am used to override the MembershipProvider but how does it work with the new SimpleMembership?

I saw there is a SimpleMembershipProvider so I think I should override it, but I don't know if the methods are for storing data purpose only or if they should contain business/validation logic)...

What about configuration? I know the InitializeDatabaseConnection method is normally responsible for initializing the whole shebang, but I don't think I should call it if I don't use Entity Framework.

Unfortunately, I did not find a lot of resources about the new SimpleMembership except two links which have not been very useful:

http://igambin.blogspot.ca/2012/08/simplemembershipprovider-huh.html

http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx

like image 793
W3Max Avatar asked Aug 29 '12 01:08

W3Max


3 Answers

So here is what I found after looking at some of the the source code (MVC4).

http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/553690ac9488#src%2fWebMatrix.WebData%2fExtendedMembershipProvider.cs

SimpleMembership is an implementation of the abstract class ExtendedMembershipProvider. The code inside SimpleMembership is mostly SQL operations and some calls to the underlying (called "previous" in the documentation) MembershipProvider.

I don't think it is of any use (in my case) to override SimpleMembership as its implementation is mostly tied to SQL Server. Instead, for what I understand, I should implement ExtendedMembershipProvider. Then, by setting this implementation in the web.config file, the WebSecurity helper would bypass SimpleMembership (default implementation) and call my implementation of the ExtendedMembershipProvider.

I don't think I will do this any soon since it looks even more complicated than before (more methods to implement)... but still doable.

However, all this said, I'm a bit disappointed that we still have to work with the MembershipProvider which, IMHO, is far (a lot of static and internal stuff) from the whole dependency injection thing that we love so much with ASP.Net MVC/WebApi.

Edit 1

This question was aked before Jon Galloway wrote this tutorial : http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx

But my answer stays valid as this (taken from Jon Galloway article) resumes it:

Note that SimpleMembership still requires some flavor of SQL Server - it won't work with MySQL, NoSQL databases, etc. You can take a look at the code in WebMatrix.WebData.dll using a tool like ILSpy if you'd like to see why - there are places where SQL Server specific SQL statements are being executed, especially when creating and initializing tables. It seems like you might be able to work with another database if you created the tables separately, but I haven't tried it and it's not supported at this point.

like image 108
W3Max Avatar answered Nov 04 '22 08:11

W3Max


Here's my implementation for mongodb. Maybe it can help https://github.com/malibeg/MongodbSimpleMembershipProvider#readme

like image 26
malibeg Avatar answered Nov 04 '22 09:11

malibeg


SimpleMembership is not really meant to be used with the old MembershipProviders as it doesn't fullfill all of the same contracts that are assumed of normal MembershipProviders. Its mostly designed for use via the WebSecurity helper.

This link might be helpful for more info: Web Pages Tutorial

like image 1
Hao Kung Avatar answered Nov 04 '22 08:11

Hao Kung