1

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");
    }
Charles
  • 50,943
  • 13
  • 104
  • 142
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • 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 Nov 29 '12 at 21:40
  • Where do I redirect though? – Ian Vink Nov 29 '12 at 21:43
  • 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 Nov 29 '12 at 21:44
  • Sorry, I mean, in the BaseController I check for Authentication, then in the BaseController, in what method do I call RedirectToAction? – Ian Vink Nov 29 '12 at 21:46
  • I don't know, your solution seems non-standard to the built in membership. – The Muffin Man Nov 29 '12 at 21:52

1 Answers1

1

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

Community
  • 1
  • 1
MVCKarl
  • 1,283
  • 9
  • 7