How should I reference an IHttpModule instance in the pipeline?

我的未来我决定 提交于 2019-12-24 09:28:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/4115955/how-should-i-reference-an-ihttpmodule-instance-in-the-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!