4

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?

seticer
  • 139
  • 1
  • 9
  • Check this url http://stackoverflow.com/questions/13155741/application-error-not-fired-for-404-page-when-extra-custom-segment – Kamlesh Dec 14 '13 at 15:03

2 Answers2

3

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 ;)

Leo
  • 14,625
  • 2
  • 37
  • 55
  • This is probably often false. A lot of requests to non-existing resources can go into the application which will then fail to resolve the path and trigger a HttpException or the like. – Alex Jul 19 '14 at 15:25
  • Set runAllManagedModulesForAllRequests to true in web.config so it hits Application_Error. – Robert Smith Aug 15 '23 at 20:00
1

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.

usr
  • 168,620
  • 35
  • 240
  • 369