Why is Response.StatusCode set to 200 when calling Application_Error ()?

In my MVC application, unhandled exceptions and the called Application_Error() handler sometimes occur.

The problem is that if I access Response.StatusCode inside Application_Error() , this happens to be 200 , although there was an unhandled exception. I would rather expect 500.

Why is it 200, although there was an unhandled exception?

+4
source share
1 answer

inside Application_Error () you can do this:

  var lastError = Server.GetLastError(); var statusCode = 500; var httpException = lastError as HttpException; if (httpException != null) statusCode = httpException.GetHttpCode(); 
0
source

Source: https://habr.com/ru/post/1500144/


All Articles