How to register HttpHandler for all subfolders in Asp.Net?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 04:01:17
Igor Brejc

Maybe you should use HttpModule instead of HttpHandler.

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>

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!