I am using the web.config code below to redirect requests to missing pages to a 404 error handling page:
<customErrors mode="On" defaultRedirect="404.aspx" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="404.aspx"/>
As dbaseman states this is because the asp.net handlers are not called for non-asp.net files. An easy way to force the asp.net handler to operate on all requests is to set the following in your web.config.
<system.webServer> <modules runAllManagedModulesForAllRequests="true"> </system.webServer>
This tells IIS to run through all of the managed modules for all requests such as .html, .jpg, .css, .js, etc. This is typically frowned upon as it just introduces extra processing and latency.
Another option to try (cleaner than the above) was posted as an answer here: http://stackoverflow.com/a/6661699/701062