I have an PhoneGap
app that is communicating with a C#
service for it's data. The user has to be logged in for them to access any of this so I have a AuthorizeAttribute
on my controller. This works fine and rightly, throws an to my app. The problem for me is that in my AuthorizeAttribute
I am overriding the HandleUnauthorizedRequest
method and it should be returning a 401. In fact, it probably is, it's just that the Ajax handler hits the error function before my override method has returned.
AuthorizeAttribute
public class AppCustomAuthorization : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
filterContext.HttpContext.Response.StatusCode = 401;
filterContext.HttpContext.Response.End();
base.HandleUnauthorizedRequest(filterContext);
}
}
Ajax
$.ajax({
type: "GET",
url: url + "checkin/app/info",
dataType: "json",
success: function(d) {
// Do stuff
},
error: function (xhr, textStatus, errorThrown) {
app.showError(errorThrown); // Status code is 0
}
});
When I look at the Network
requests, it seems that my get request is cancelled. Originally, I assumed this is because my authorize attribute is causing it cancel the request, but then, it seems to cancel before it hits my handler.