After doing a little research based on Alexander's answer, I also implemented IHttpHandler in my AspExceptionHandler.
Now my class is as follows:
public class AspExceptionHandler : IHttpModule, IHttpHandler { public void Dispose() { } public void Init(HttpApplication context) { context.Error += new EventHandler(ErrorHandler); } private void ErrorHandler(object sender, EventArgs e) { HttpApplication application = (HttpApplication)sender; try {
In the ProcessRequest method (IHttpHandler required) I check if the file exists. If this does not exist, I will throw an HttpException, which is caught by the HttpModule part of my class.
The system.webServer node in my web.config now looks like this:
<modules runAllManagedModulesForAllRequests="true"> <add name="AspExceptionHandler" type="Company.Exceptions.AspExceptionHandler, Company.Exceptions" preCondition="managedHandler" /> </modules> <handlers> <add name="AspExceptionHandler" type="Company.Exceptions.AspExceptionHandler, Company.Exceptions" verb="*" path="*.html" /> </handlers>
I found the answer in this post: HttpHandler runs only if the file does not exist
source share