Question

Am new at ASP.NET MVC development.

For my 5 Internet application I have created a custom as my user-related in my contains additional columns which are not supported by the out-of-the-box provided by ASP.NET ()

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?

Was it helpful?

Solution

In a MVC 5 project I would recommend looking into using ASP.NET-IDENTITY rather a custom membership provider. It is easily customizable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top