下面是一段自定义的httpmodule
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 namespace WebLibrary.Modules 2 { 3 public class MSNModule : IHttpModule 4 { 5 /// <summary> 6 /// You will need to configure this module in the Web.config file of your 7 /// web and register it with IIS before being able to use it. For more information 8 /// see the following link: http://go.microsoft.com/?linkid=8101007 9 /// </summary> 10 #region IHttpModule Members 11 12 public void Dispose() 13 { 14 //clean-up code here. 15 } 16 17 public void Init(HttpApplication app) 18 { 19 app.BeginRequest += app_BeginRequest; 20 } 21 22 void app_BeginRequest(object sender, EventArgs e) 23 { 24 25 } 26 27 #endregion 28 } 29 }
下面2种注册方式
- 在site目录的webconfig中添加如下结点
View Code
<system.web> <httpModules> <add name="MSNModule" type="WebLibrary.Modules.MSNModule"/> </httpModules> </system.web>
格式就是: <add name="<httpmodule类名>" type="<命名空间.httpmodule类名>,<程序集名>"/>
- http://www.cnblogs.com/lyk831216/archive/2011/08/01/2124181.htm
注意: 似乎httpmodule不能在子目录下的webconfig中注册,因为site运行时只会加载一次httpmodule(读取site目录的webconfig)