Asp – EndRequest not fired on IIS when resource is missing

asp.nethttp-status-code-404httpmoduleiis-6net

I have a HttpModule that hooks on to the EndRequest Event on a IIS6 with a wildcard handler registered and it works fine as long as the request ends on a .aspx page, but NOT if the url is missing (404).

I guess it's because of the staticfilehandler ends the request, but is there any good solution for this problem ?

I have tried the same solution in IIS7 (pipeline mode) and there it works fine.

Best Answer

First thing I'd try, is to tell IIS not to verify the file exists, which would allow the request to pass through to the HttpModule. You can do this for any particular file mapping, including the wildcard.

If the above isn't an option, worse case scenario you could add a default handler for the 404 error in the web.config, so that if the HttpModule can't catch the event, you still have a chance to 'do something'. Depending on what you are trying to accomplish in the EndRequest event, you may still be able to use the workaround.

<customErrors defaultRedirect="ErrorPage.aspx" mode="On">   
    <error statusCode="404" redirect="filenotfound.aspx" />
</customErrors>
Related Topic