I've been looking around various SO questions, blog posts, and so forth regarding the changes to membership providers in MVC 4. While I like many of the changes and the simplification of things (particularly the out-of-the-box external login support), I'm as yet unable to find one seemingly-simple thing...
How can I override the membership/role provider with a custom one that uses another data source?
I don't want to replace WebSecurity
or anything that drastic, since it handles all of the things I want it to handle. (Cookie management, for example.) I don't want to do anything that will break the existing support for external login providers, as my application uses those in conjunction with local logins. All I'm looking to do is interject between the membership system and the database behind it and customize that data fetching.
The tables that it creates by default are:
- UserProfile
- webpages_Membership
- webpages_OAuthMembership
- webpages_Roles
- webpages_UsersInRoles
And while that works, I have cause to abstract this behind some custom objects and break the coupling between the application and the database. (Basically, I have some custom domain models full of business logic which should handle all of this, and I want the membership/role system to use those models instead of the database. Those models might get their persisted data from a database, they might not. That shouldn't matter.)
Most of the references I find for customization claim that it's easy to do, all I have to do is modify the UserProfile
model, include my new custom fields in various calls, and update the call to InitializeDatabaseConnection
to point it to my database schema.
But I'm not using a database. (Or, more specifically, as far as the application layer is concerned there's no such thing as a database. Only my domain models.) So that easy customization doesn't really change anything.
Is there a way to interject between the membership system and the database so I can make a custom data provider for the existing membership provider?