Reputation: 7979
$.ajax({
type: "POST",
url: "/Controller/Methods/" + $('#FrameworkId').val() + "/10/" + $('#category').val(),
success: function(data) {
alert("sucess")
},
error:function(data) {
alert(data.statuscode)
}
});
And in server side
suppose in server side In the action i am just doing
filterContext.HttpContext.Response.StatusCode = 401;
throw new UnauthorizedAccessException("Login_Expired");
Still alert(data.statuscode)
gives 500
What can I do to get 401 as I set it?
Upvotes: 1
Views: 633
Reputation: 105071
Don't throw the exception in your action filter.
What is the nature of you action filter anyway? Here's an example of an exception filter that returns a 400 back to the client.
Not directly related but just FYI. HttpUnauthorizedResult
which is part of Asp.net MVC framework does this the same way:
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.HttpContext.Response.StatusCode = 0x191;
}
As you can see it only returns an appropriate status code. Not exceptions thrown.
Upvotes: 2