11

I would like to register an HttpHandler to include all subfolders of a root folder regardless of how far down they are nested. I would have expected the behavior with the below code to do just that but in fact it only includes items directly in the root folder.

<httpHandlers>
  <add verb="*" path="root/*" type="HandlerType, Assembly" />
</httpHandlers>

I can of course register as below to include anything that is second tier, however have yet to encounter a way to just say anything below root.

<httpHandlers>
  <add verb="*" path="root/*/*" type="HandlerType, Assembly" />
</httpHandlers>

This is something hat has been bugging me for quite a while and I would love to hear of a simple solution.

I would like to clarify that when I say "root" I do not mean the root of the application and am not necessarily interested in sending all requests in the application to a module to be processed.

YonahW
  • 15,790
  • 8
  • 42
  • 46

4 Answers4

22

You don't need a separate web.config. Use the <location> element in your primary web.config:

<!-- Configuration for the "root" subdirectory. -->
<location path="root">
  <system.web>
    <httpHandlers>
      <add verb="*" path="root" type="HandlerType, Assembly"/>
    </httpHandlers>
  </system.web>
</location>
Kevin P. Rice
  • 5,550
  • 4
  • 33
  • 39
6

You can create web.config in this "root" folder with path="*"

  • 1
    that is a great idea although in my case I am dealing with a url that does not match up to a folder. – YonahW Oct 14 '09 at 22:42
0

You could create a http module that checks the url for every incoming request. If the request url is in any folder you want your handler to handle, it does this:

  • Put the full, original url in Context.Items
  • Change the request path to some dummy value immediately below the handler's folder, matching the handler's configuration.

The handler will now be called, and it will find the dummy url in the request. It ignores this url, and processes the actual url that it will find in Context.Items.

0

Maybe you should use HttpModule instead of HttpHandler.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
Igor Brejc
  • 18,714
  • 13
  • 76
  • 95
  • This is of course always an option but I do not need the handler for all requests in the application just for all requests below a specific folder. I might have been unclear in my question, by "root" I don't mean root of the site just of that branch in the folder tree. – YonahW Apr 03 '09 at 13:57