Problem using custom HttpHandler to process requests for both .aspx and non-extension pages in IIS7

1.1k views Asked by At

I am trying to process both ".aspx" and non-extension page requests (i.e. both contact.aspx and /contact/) using a custom HttpHandler in IIS7. My handler works just fine in either one case or the other, but as soon as I try to process both cases, it only works for one. Please see Handlers snippet from my web.config below:

If i keep only mapping to "*.aspx" then all .aspx requests are processed correctly, but obviously extensionless requests won't work:

<add name="AllPages.ASPX" path="*.aspx" verb="*" type="Test.PageHandlerFactory, Test" preCondition="" />

If i change the mapping to "*" then all extensionless requests are processed correctly, but ".aspx" requests that should still be handled by this handler stop working. Note that i added the StaticFiles entry in order to process files that are on disk like images, css, js, etc.

<add name="WebResource" path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" />
<add name="StaticFiles" verb="GET,HEAD" path="*.*" type="System.Web.StaticFileHandler" resourceType="File" />
<add name="AllPages" path="*" verb="*" type="Test.PageHandlerFactory, Test" preCondition="" />

The crazy thing is that when i load an ".aspx" request (with the 2nd configuration shown) IIS7 gives a 404 not found error. The error also says that the request is processed by the StaticFiles handler. But I made sure to add resourceType="File" to the StaticFileHandler in order to avoid this. According to MS this means the request is only for "physical files on disk". Am i misreading/interpreting the "on disk" part?

My .aspx file isn't on disk, that's why i want to use the handler in the first place.

1

There are 1 answers

0
Chris Eldredge On BEST ANSWER

The 2nd configuration will cause *.aspx get handled by StaticFileHandler because the files do exist so they meet the criteria for the handler. However, the handler is configured not to serve these files and produces a 404 message instead.

A better solution would be to use an HttpModule implementation such as URL Rewrite Module to rewrite virtual paths to pages or handlers.