问题
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