Created On:
Aaron Robson
aspnet, HttpHandlers, IIS

StaticFileHandler vs DefaultHttpHandler

If you map a specific request type - say .txt - to aspnet_isapi.dll in IIS, then the DefaultHttpHandler is invoked if no other Handler is configured. This Handler reverts requests back to IIS after running through the front part of the aspnet processing pipeline. This can cause some strange behaviour with regard to infinite loops, and the returned document is usually empty - although returned with a 200 OK status code. Apparently the wildcard mapping (.*) has some special logic in IIS to break said loops.

I had this issue with a robots.txt file. From a browser the returned document was indeed empty, and looking at the http headers, everything was ok. However google would see the returned document as having a 500 internal server error status code.

The fix was simply to map the StaticFileHandler within the system.web section of the web.config:

    <add path="*.txt" verb="GET,HEAD" type="System.Web.StaticFileHandler" validate="true" />

Hope this helps.