I am building a multi-tenant site with MVC3. Prior to this project, I never touched the .NET stack or the web development in general, as you can imagine that I don't have enough domain knowledge.
I still use the default AccountController system by default, but I quickly decided that I did not want to use aspnetdb.mdf for authentication, as its design is very different from my requirements. I need role-based authentication, so I ended up writing the User and Role user classes as Entity class classes and used this tutorial to configure custom MembersProvider and RoleProvider.
Everything is working fine now, but as I create feature-rich features, it becomes more messy. Based on in this example , I use a custom controller extension that keeps track of which tenant is using this session, and all my controllers extend this class instead of the base class of the controller.
All tenants use the same database. Each object has a Tenant property that identifies to whom it belongs.
So here is the problem:
Usernames do not have to be globally unique. Only a combination of username and tenant should be unique. Therefore, ValidateUser needs to know the username, password and tenant. Since my user MembershipProvider is not a controller, it does not know which tenant is using the session, and the ValidateUser method only accepts a username and password, so I cannot pass this information to it.
In addition, almost everything that is part of the MembershipProvider, in addition to ValidateUser, is already implemented in the UserRepository class, which this tutorial told me about. I prefer the repository template, and this is more convenient than sticking to the MembershipProvider interface, but now there is a serious conflict of interest between UserRepository and MembershipProvider.
So my question is:
Do I need to use MembershipProvider or even membership? It seems that all MembershipProvider members will be executed more conveniently using my repository class. At this point, I still have to write a new Authorize attribute that does not rely on membership, and everything should work without any MembershipProvider element, right? If I do not lose my membership, I am forced to completely cripple my MembershipProvider implementation to such an extent that it still does not look like the original interface.
... Either this or membership does a ton of things that I donβt know about, and removing them is blatant stupidity. This is also a great opportunity.