Question is: Why is custom Error handling not working for non-existing paths/directories?
Updated with fixed code (thanks to everyone for you input):
From this comment to Mr. Disappointment:
Thanks, I'm using IIS 7 local and IIS 7.5 on live. Let me know when you find the material.
If your application is running in an application pool configured to run in Classic Pipeline mode then content not intended for ASP.NET won't hit the ASP.NET runtime. i.e. folders that don't exist. These will be handled directly by IIS.
You have a couple choices:
Set the application pool to Integrated Pipeline mode. You may also need to configure the following setting if IIS's error handling "eats" your ASP.NET 404 and 500 status code from ASP.NET:
If the application is not well behaved in "Integrated Pipeline" mode but you're just concerned about getting a page displayed for a 404 response then configure the following:
You'd need to set the 404
status code in the page, otherwise it'll just return a 200
.
If you use a static page, for example:
This will return a 404
.
If the application is not well behaved in "Integrated Pipeline" mode AND you absolutely must pass 404 errors through your error handler then you may have to manually map wildcard content to the ASP.NET HttpHandler so that such requests do hit the pipeline. This would be a sub-optimal solution.