Here is my problem:
I have an intranet application which utilizes Windows Authentication.
Users can access a public area and then there is an elevated area.
In order to provide custom authorization handling, I created this authorization attribute:
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
base.HandleUnauthorizedRequest(filterContext);
if (filterContext.HttpContext.User.Identity.IsAuthenticated)
{
filterContext.Result = new RedirectResult("Error/Unauthorized");
}
}
That's straight forward and works if a user inputs invalid credentials.
However, if a user clicks cancel, it instead goes to the standard 401 page.
I have tried adding in
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
However, this won't allow a user to enter any credentials and just performs the redirect.
My question is: how do I handle the clicking of the "cancel" button for the Windows Authentication gracefully?