我应该如何在管道中引用 IHttpModule 实例?

发布于 2024-09-30 23:37:21 字数 385 浏览 0 评论 0原文

我创建的 IHttpModule 实现

public class ResponseTweaker : IHttpModule {  // my module ...

已在 Web.config 中注册

<system.web>
  <httpModules>
      <add name="redman" type="ResponseTweaker"/>
  </httpModules>

,并且它的实例位于管道中。

从调用者的角度来看(例如从 Global.asax.cs 文件),我应该如何获取对该模块实例的引用?

An IHttpModule implementation I created

public class ResponseTweaker : IHttpModule {  // my module ...

is registered in Web.config

<system.web>
  <httpModules>
      <add name="redman" type="ResponseTweaker"/>
  </httpModules>

and an instance of it is sitting in the pipeline.

From the perspective of a caller (e.g. from the Global.asax.cs file), how should I get a reference to that module instance?

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

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

发布评论

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

评论(1

她如夕阳 2024-10-07 23:37:21

这些模块可以在 HttpContext.Current.ApplicationInstance.Modules 中找到。

您可以查看HttpModuleCollection,或使用名称语法:
HttpContext.Current.ApplicationInstance.Modules[“redman”]。您可能需要将返回的 IHttpModule 转换为 ResponseTweaker 类型。

如果类型可能有所不同,请搜索集合以查找与所需类型匹配的模块。

The modules can be found in HttpContext.Current.ApplicationInstance.Modules.

You can look through the HttpModuleCollection, or use the name syntax:
HttpContext.Current.ApplicationInstance.Modules["redman"]. You will probably need to cast the returned IHttpModule to type ResponseTweaker.

If the type may vary, search the collection to find module(s) matching the desired type.

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