I have an MVC4 application to which I added an HttpHandler
:
<system.web>
...
<httpHandlers>
<add path="Files" verb="*" type="MyHttpHandler" />
</httpHandlers>
</system.web>
I also ignored the relevant path in RegisterRoutes
so that the requests to "Files" are not handled by MVC:
routes.IgnoreRoute("Files/{*pathInfo}");
The problem is that the MyHttpHandler
is invoked only for requests to "Files", not for any of its children or sub-folders.
I've tried using the <location>
element, but getting that to work means that you will be hard coding the application's virtual path in the "path" attribute (e.g., <location path='MyApp\Files'>
).
What is the correct method to use to allow all requests for "Files" and any of its sub-folders (and sub-folders of those folder, etc) to get routed to MyHttpHandler
?
Scratch that...<location>
seems to work OK. Though, you need both the <web>
and <webServer>
entries to ensure that it works for both IIS and the Visual Studio Development Server. For example:
<location path="Files">`
<system.webServer>
<handlers>
<add name="MyHandler" path="*" verb="*" type="MyHttpHandler" />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="MyHttpHandler" />
</httpHandlers>
</system.web>
</location>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With