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

Joh*_*n K 1 .net c# asp.net httpmodule

我创建的IHttpModule实现

public class ResponseTweaker : IHttpModule {  // my module ...
Run Code Online (Sandbox Code Playgroud)

在Web.config中注册

<system.web>
  <httpModules>
      <add name="redman" type="ResponseTweaker"/>
  </httpModules>
Run Code Online (Sandbox Code Playgroud)

它的一个实例就是在管道中.

从主叫方(例如,从文件的Global.asax.cs)的角度来看,如何应该我去该模块实例的引用?

Jas*_*aty 5

这些模块可以在HttpContext.Current.ApplicationInstance.Modules.

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

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