Search code examples
asp.net-mvcasp.net-mvc-4windows-authentication

MVC4: When to redirect failed login


I am using MVC4 with Windows Authentication for an Intranet site.

My Controllers are based on my BaseController

BaseController will call out to a service to see if the Windows user is allowed to use the site. If not, I want to redirect them to "Index" on the Controller "UnAuthorized"

Where in the BaseController would I check and then how would I redirect the request to the UnAuthorized controller?

I have tried to redirect in the OnAuthorized like this but nothing happens:

    protected override void OnAuthorization(AuthorizationContext filterContext)
    {
        base.OnAuthorization(filterContext);

        if (!isAuthorized(username))
            RedirectToAction("Index", "UnAuthorized");
    }

Solution

  • This answer will probably help you

    Redirect Unauthorised Controller in MVC

    Also This video will give you some general help

    windows authentication in ASP.NET MVC 3