如何为Asp.Net中的所有子文件夹注册HttpHandler?

发布于 2024-07-16 02:39:27 字数 543 浏览 7 评论 0原文

我想注册一个 HttpHandler 以包含根文件夹的所有子文件夹,无论它们嵌套的深度如何。 我本希望下面的代码的行为能够做到这一点,但实际上它只包含直接位于根文件夹中的项目。

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

我当然可以按如下方式注册以包含第二层的任何内容,但是还没有遇到一种仅在根目录下说出任何内容的方法。

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

这是困扰我很长一段时间的问题,我很想听到一个简单的解决方案。

我想澄清的是,当我说“root”时,我并不是指应用程序的根,也不一定有兴趣将应用程序中的所有请求发送到要处理的模块。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

じее 2024-07-23 02:39:27

您不需要单独的 web.config。 使用<位置> 主 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 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>
如日中天 2024-07-23 02:39:27

您可以在这个“根”文件夹中使用路径=“*”创建web.config

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

请你别敷衍 2024-07-23 02:39:27

也许您应该使用 HttpModule 而不是 HttpHandler。

Maybe you should use HttpModule instead of HttpHandler.

许久 2024-07-23 02:39:27

您可以创建一个 http 模块 来检查每个传入请求的 url。 如果请求 url 位于您希望 处理程序 处理的任何文件夹中,它会执行以下操作:

  • 将完整的原始 url 放入 Context.Items
  • 将请求路径更改为处理程序文件夹正下方的某个虚拟值,匹配处理程序的配置。

现在将调用处理程序,它将在请求中查找虚拟 URL。
它忽略此 url,并处理它将在 Context.Items 中找到的实际 url。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文