global.asax Application_Error not firing global.asax Application_Error not firing asp.net asp.net

global.asax Application_Error not firing


If you do not have a customErrors section in your Web.config, it is the same as having the section with mode="RemoteOnly". This customError mode will make local requests (made from the server running IIS) not use custom errors and it will execute the Application_Error() method as expected. Remote requests will use customErrors and not execute the method mentioned above.

This explains why you are seeing different behavior locally than on your server. You can reproduce this behavior on any environment by changing the customErrors mode to On or Off explicitly. On will not execute the Application_Error() section while Off will.

<customErrors mode="On|Off|RemoteOnly" />

This doesn't solve your problem of course, which is you want the method to be executed regardless. I have a bounty on another question where we are trying to figure out why the Application_Error() method is not firing when customErrors mode is On. Check back there in a couple days to see if we have found a solution.


If you are using IIS 7, try setting:

Response.TrySkipIisCustomErrors = true;


If you previously deployed your application as precompiled but now you are not, then yes, you need to delete PrecompiledApp.config and your Deployment.dll in the bin directory. .NET will use the global code in Deployment.dll instead of your changes.