17

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

W3Max
  • 3,328
  • 5
  • 35
  • 61
  • 2
    Jon Galloway of Microsoft has posted some very helpful insight into SimpleMembership at 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 – Ingo Aug 30 '12 at 05:59

3 Answers3

11

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.

John B
  • 20,062
  • 35
  • 120
  • 170
W3Max
  • 3,328
  • 5
  • 35
  • 61
  • 14
    Why oh why would you force a int as user ID - ExtendedMembershitProvider!? – W3Max Aug 31 '12 at 01:09
  • I am doing the same as this question. Have you started any code with the `ExtendedMembershipProvider`? –  Mar 24 '15 at 06:50
4

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

malibeg
  • 2,237
  • 2
  • 17
  • 21
  • 1
    Thanks! I have done a similar implementation for RavenDB... I'm just to lazy to share it on GitHub (one day I will). I am sure your post will help someone! – W3Max Jan 11 '13 at 13:13
  • Too lazy? lol Can you post it to a blog? That would really help some raven users.... – bbqchickenrobot Feb 18 '13 at 19:33
1

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

Hao Kung
  • 28,040
  • 6
  • 84
  • 93
  • Thanks, but I know all of this. I also know that SimpleMembership is a layer on top of the old MembershipProvider. I just want to override the data layer (SQL CRUD). I will try to override the class SimpleMembershipProvider tonight and post the result here for future reference. – W3Max Aug 29 '12 at 21:00
  • 3
    If that's what you want, you might be able to just implement your own ExtendedMembershipProvider(that extends SimpleMembership if possible) and hook it into WebSecurity via registering it as the Membership.Provider – Hao Kung Aug 29 '12 at 21:25