I am building MVC web application that for at least part of its data transfer relies on Ajax.
The controller action is
[RBAC]
[Authorize]
public string GetData(string inputdata)
{
some code ...
return jsondata;
}
The ajax call is
$.ajax({
dataType: "json",
url: Url,
data: { '_inputdata': selectedText },
success: function (data)
{
response($.map(data,
function(item, index) {
return {
label: item.label,
value: item.value
}
}));
},
error: (function (jqXHR, textStatus, errorThrown, data) {
ProcessFail(jqXHR, textStatus, errorThrown, data);
});
})
});
[RBAC] causes an authorization check to be done which is what I want.
public override void OnAuthorization(AuthorizationContext filterContext)
{
......
filterContext.Result = new RedirectToRouteResult
(new RouteValueDictionary { { "action", "Index" },
{ "controller", "Unauthorised" } ,
{ "Area", String.Empty }});
.....
}
The problem is that I don't get anything back at the ajax except a failure. There is nothing that tells me that there was an authorization error.
Questions:
- Is it possible to get back information from an authorization failure into the ajax response. If so how?
- If the answer to 1. is no, should I be checking for this authorization before I make this call?
As always, any help appreciated.