Reputation:
Am new at ASP.NET MVC development.
For my asp.net-mvc 5 Internet application I have created a custom membership-provider as my user-related datatables in my database contains additional columns which are not supported by the out-of-the-box membership-provider provided by ASP.NET (simplemembership)
I'm more or less following the implementation method of this blog, Implementing your own RoleProvider and MembershipProvider in MVC 3 (though I know that I'm working with MVC 5).
In the blog at the section titled "Modifying the AccountController to use our new Providers" he inserts the following code in the Initialize
method of his AccountController
[C#]
public LocalBankMembershipProvider MembershipService { get; set; }
public LocalBankRoleProvider AuthorizationService { get; set; }
protected override void Initialize(RequestContext requestContext)
{
if (MembershipService == null)
MembershipService = new LocalBankMembershipProvider();
if (AuthorizationService == null)
AuthorizationService = new LocalBankRoleProvider();
base.Initialize(requestContext);
}
The above allows the author of the blog to use his custom membershipprovider's methods in that controller.
If following this bloggers example of how to implement a custom membershipprovider is pretty much the way to go, I was wondering if I have to initialize my custom providers in each and every Controller or does there exist a more elegant way of implementing it in my Controllers?
Upvotes: 2
Views: 3134
Reputation: 11568
In a MVC 5 project I would recommend looking into using ASP.NET-IDENTITY rather a custom membership provider. It is easily customizable.
Upvotes: 3