In my MVC application I sometimes have unhandled exceptions and Application_Error()
handler invoked.
The problem is if I access Response.StatusCode
inside Application_Error()
it happens to be 200
although there was an unhandled exception. I'd rather expect 500.
Why is it 200 although there was an unhandled exception?
inside Application_Error() you may do this:
var lastError = Server.GetLastError();
var statusCode = 500;
var httpException = lastError as HttpException;
if (httpException != null)
statusCode = httpException.GetHttpCode();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With