5

I use ASP.NET MVC 3 for an application which makes heavy use or Users and Roles.

To create a user and assign role(s) I use the standard process via ASP.NET Membership.

Throughout the entire app I use NHibernate for the underlying data access except the places were the default MembershipProvider and RoleProvider implementations are used (inside the AccountController which delegates calls to those implementations).

I would like to use NHibernate in order to be able to read/edit/modify the values on that tables which are managed by ASP.NET Membership.

I found two solutions:

  1. Write a custom NHibernate implementation for MembershipProvider and RoleProvider (or even use this one). That's the hardest path.

  2. Map only the tables (as described here) and then use NHibernate directly (although any default actions from AccountController will still handled by the default providers).

Any suggestions/recommendations?

Nikos Baxevanis
  • 10,868
  • 2
  • 46
  • 80

1 Answers1

3

I've used the custom provider you link with pretty good success. I did make a few changes to it, so that it would use a single session for its lifetime.

If you want to use ASP.net membership I think that approach is your best bet, mainly for portability (it doesn't rely on any SP's being present in your database). I'm currently using the modified provider from that link against MSSQL and Postgres with no problems, and I've used it against MySQL as well.

AlexCuse
  • 18,008
  • 5
  • 42
  • 51
  • I am writting unit-tests for this implementation, and yes it works great out of the box :-) (so far). – Nikos Baxevanis Jun 20 '11 at 08:32
  • Awesome, glad its working. I never got around to writing tests around it, feel free to post yours :D – AlexCuse Jun 21 '11 at 12:30
  • 2
    I am planning to share the project on github the soonest. :-D – Nikos Baxevanis Jun 22 '11 at 08:10
  • Cheers, please post back here if you do! – AlexCuse Jun 22 '11 at 14:48
  • I decided not to do it. Mostly because of this http://blogs.teamb.com/craigstuntz/2010/03/05/38558/ However, I provide some Fluent NHibernate configuration and mapping here http://www.nikosbaxevanis.com/bonus-bits/2011/06/dont-rely-on-sql-membership-provider-database-schema.html – Nikos Baxevanis Jun 24 '11 at 07:12
  • Probably a fair argument, though with an ORM a schema change isn't usually too difficult. Thanks for posting the code though, I'll take a look. – AlexCuse Jul 15 '11 at 01:46