The problem is the request processing order. IIS7 processes requests in the order specified by the IIS Handlers configuration item. By default, the IIS configuration handler element contains
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
at the end of handlers. Therefore, a whole request that does not match the previously specified handler will be processed by this handler (including also the folder request).
You can remove all default handlers by using the element to clear handlers in the configuration and specify your own request processing order.
I recommend copying the default IIS handler configuration (C: \ Windows \ System32 \ inetsrv \ config \ applicationHost.config) to your web configuration without the StaticFile handler at the end.
Then you must add a special static content handler for each static content type (jpg, gif, js, css).
<add name="StaticFile-swf" path="*.swf" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> <add name="StaticFile-png" path="*.png" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> <add name="StaticFile-gif" path="*.gif" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> <add name="StaticFile-jpg" path="*.jpg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> <add name="StaticFile-css" path="*.css" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> <add name="StaticFile-js" path="*.js" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
and a managed handler (PageHandlerFactory) for folder requests after that.
<add name="PageHandlerFactory-Folders" path="*" verb="*" type="System.Web.UI.PageHandlerFactory" modules="ManagedPipelineHandler" resourceType="Unspecified" requireAccess="Read" allowPathInfo="false" preCondition="integratedMode" />
At the end, you should also add a StaticFile handler.
Here is an example.
Peter Starbek
source share