Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application_Error is not fired on 404 error

I use an Application_Error handler to log all unhandled exceptions; generally it works well, but 404 errors always are skipped. Any ideas what might be the reason?

like image 440
seticer Avatar asked Oct 19 '25 04:10

seticer


2 Answers

Actually, that is because that's an http protocol error returned by your web server. It's not a .net framework exception and thus it can't be handled by asp.net. However, you can configure IIS to serve a custom page when it returns a 404 error and this can be done through your web.config file. Needless to say that this custom page could be an aspx page where you can add some custom processing such as logging the error ;)

like image 109
Leo Avatar answered Oct 21 '25 18:10

Leo


404's are not always caused by exceptions. You can just set the Response.Status* fields to generate a 404 response.

Use Application_EndRequest to examine the response and act on it.

like image 32
usr Avatar answered Oct 21 '25 19:10

usr