How throw custom http status code during Ajax(Post) request?

First things first HttpStatusCode. Unauthorized = 401 not 403 status code. There is an important distinction between those 2 codes.

First things first HttpStatusCode. Unauthorized = 401, not 403 status code. There is an important distinction between those 2 codes.

When you set the status code to 401 some nasty things happen: you automatically get redirected to the Login page by the ASP. NET Forms authentication module => the login page is served with status code = 200. Phil Haack addressed this issue in the following blog post.As far as throw new HttpException((int)HttpStatusCode.

Forbidden, "Forbidden"); is concerned in your controller action, well, you throw an exception that is of type HttpException and whose StatusCode is set to 401 but other than that there is absolutely nothing that will catch this exception and set the corresponding response status code. So the exception bubbles up and since you don't presumably have a global exception handler it is translated as a 500 error page by the server. Here's an example of a global exception handler that you might find useful.

Thx. I don't want redirect while HttpStatusCode. Unauthorized error, because in client in this case I get the login page and 200 ( success ) result.

I want translate my custom codes in error ajax function-callback, but web server always notify me as 500 status code. In controller I can catch 2 exceptions ( access, and internal error ) and in client code I need translate it. – Kronos Dec 1 '11 at 8:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions