Brief:
I have a sub classed AuthorizeAttribute in my framework in which I am doing custom authorization.
I am in the process of switching from normal asp.net mvc view rendering to Ajax rendering via jQuery. Hence every link in the application does a ajax call to get the data.
In order to cater for this I have converted most of my pages to partial views so that each ajax request only gets the portion that needs to be updated on the page.
During the normal view rendering when a request was unauthorized it was being redirected to the logon page described in the web.config. After converting to Ajax things are a bit different as I dont want the markup for the logon page in the ajax request but want a structured response in it so that I can act accordingly inside the ajax call.
In order to do this I believe I have to override the HandleUnauthorizedRequest method in the sub classed AuthorizeAttribute class and set the filterContext.Result to a json result. But in doing so how would I get to distinguish between a unauthorized request and a successfull request, because from the ajax calls point of view both are successful responses; hence will be handled in the success handler.
What would be the correct way to deal with this issue?