从 ac# .net 应用程序中的 ihttpmodule 检测映射的虚拟目录

发布于 2024-08-20 04:28:02 字数 704 浏览 2 评论 0 原文

我有一个 .net 网站,其中包含我编写的用于执行某些任务(授权等)的 IHttpModule。但在网站内有许多虚拟目录映射到第三方应用程序,遗憾的是我无法更改或移动这些应用程序(例如社区服务器论坛、adxstudio cms 等)。

我正在寻找一种方法来阻止我的 IHttpModule 在对这些虚拟目录的内容发出请求时运行。这可能吗?

[编辑 - 添加以下内容]

我一直在尝试在 Web.config 中的 节点内添加 文件在虚拟目录应用程序中,但似乎不起作用。它可能也不是一个很好的解决方案,因为第三方应用程序可以更新,所以我不想要求更改他们的代码/配置。

我还尝试添加 节点周围继承了 InChildApplications="false"> 但这似乎也不起作用。

[再次编辑 - 添加更多]

原因是不起作用是因为 IHttpModule 的 Init 事件仅在每个应用程序生命周期(而不是我假设的每个请求)触发一次。由于我在 init 事件中添加了一堆事件侦听器,这些侦听器仍然会在后续请求中触发......

I have a .net website which contains an IHttpModule I wrote to do certain tasks (authorisation etc). But within the website there are a number of virtual directories that are mapped to third party applications which unfortunately I can't change or move (e.g. community server forums, adxstudio cms and others).

I am looking for a way to prevent my IHttpModule from running when requests are made for the contents of those virtual directories. Is this possible?

[Edit - added the following]

I have been experimenting with adding <remove name="X"/> inside the <httpModules> node in the Web.config files in the virtual directory applications but it doesn't seem to be working out. It probably isn't a great solution either because the third party applications can be updated so I don't want to require changes to their code/ configuration.

I also tried adding a <location path="." inheritInChildApplications="false"> around my <system.web> node in the parent Web.config but that also didn't seem to work.

[Edit again - added more]

The reason is doesn't work is because the IHttpModule's Init event is only fired once per application lifecycle (rather than per request as I had assumed). Since I add a bunch of event listeners in the init event these are still fired on subsequent requests...

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

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

发布评论

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

评论(1

极致的悲 2024-08-27 04:28:02

如果您有这些目录及其虚拟路径的列表,则可以构建它们的查找。

对于触发模块的每个 HttpRequest,您可以检查虚拟路径以查看它是否属于查找中的任何路径。如果是,那么您可以不执行任何操作或退出模块的代码。

PS:对于性能问题,您可能希望将查找存储在应用程序状态中(例如哈希图等)

If you have a list of these directories and their virtual paths, you can build a lookup of them.

For every HttpRequest that triggers your module, you can check for the virtual path to see if it belongs to any of the path in the lookup. If yes, you can then do nothing or exit your module's code.

PS: For performance issue, you probably want to store the lookup in the application state (e.g. hashmap etc)

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