1
votes

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");
    }
1
Are you manually calling out to this service to see if the user is authorized? If so then you redirect when you get the response back. - The Muffin Man
Where do I redirect though? - Ian Vink
You redirect back to your login page and notify the user that their username/password was incorrect. If they tried to access a page without being logged in then you redirect to the login page and notify the user that they must login to access the other page. - The Muffin Man
Sorry, I mean, in the BaseController I check for Authentication, then in the BaseController, in what method do I call RedirectToAction? - Ian Vink
I don't know, your solution seems non-standard to the built in membership. - The Muffin Man

1 Answers

1
votes

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