开发者

How should I reference an IHttpModule instance in the pipeline?

An IHttpModule implementation I created

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

is registered in Web.config

<system.web>
  <httpModules>
      <add name="redman" type="ResponseTweaker"/>
  <开发者_StackOverflow中文版/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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜