我应该如何引用在管道的IHttpModule的实例? [英] How should I reference an IHttpModule instance in the pipeline?

查看:114
本文介绍了我应该如何引用在管道的IHttpModule的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是IHttpModule的实施,我创建

An IHttpModule implementation I created

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

登记在Web.config中

is registered in Web.config

<system.web>
  <httpModules>
      <add name="redman" type="ResponseTweaker"/>
  </httpModules>

和它的一个实例是坐在流水线。

and an instance of it is sitting in the pipeline.

从来电者的角度来看(例如从的Global.asax.cs文件),如何的的我得到的引用,该模块实例?

From the perspective of a caller (e.g. from the Global.asax.cs file), how should I get a reference to that module instance?

推荐答案

该模块可在 HttpContext.Current.ApplicationInstance.Modules 找到。

您可以去翻 HttpModuleCollection ,或使用名称语法: HttpContext.Current.ApplicationInstance.Modules [雷德曼] 。你可能需要转换返回 IHttpModule的键入 ResponseTweaker

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.

这篇关于我应该如何引用在管道的IHttpModule的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆