My ASP MVC (1.0) website has a default login page (based on OpenId - but that shouldn't make a different). It works fine when AuthorizedAttribute is on the Action/Controller.
However, I have AJAX requests coming in as well. Here is what I do with them:
if (Request.IsAjaxRequest())
{
if (Request.IsAuthenticated)
{
// Authenticated Ajax request
}
else
{
// Non-authenticated Ajax request.
Response.StatusCode = (int)HttpStatusCode.Unauthorized;
return Json(new { response = "AUTHENTICATION_FAILED" });
}
}
The problem is if I set the Response.StatusCode to Unauthorized, the request is redirected to my login page which is not good for Ajax requests.
Any suggestions for this issue is appreciated.