我应该如何在管道中引用 IHttpModule 实例?
我创建的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些模块可以在
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 returnedIHttpModule
to typeResponseTweaker
.If the type may vary, search the collection to find module(s) matching the desired type.