日期:2010-01-01  浏览次数:20701 次

C#过滤器HttpModule的使用,如下代码示例:

  1. using System; 
  2. using System.Web; 
  3.  
  4. public class HttpModule:IHttpModule 
  5. { 
  6.      public void Dispose() 
  7.      { 
  8.      } 
  9.  
  10.      public void Init(HttpApplication application) 
  11.      { 
  12.          application.BeginRequest+=new EventHandler(Application_BeginRequest); 
  13.          application.EndRequest+=new EventHandler(Application_EndRequest); 
  14.      } 
  15.  
  16.      void Application_BeginRequest(Object source,EventArgs e) 
  17.      { 
  18.       HttpApplication application=(HttpApplication)source; 
  19.       HttpContext context=application.Context; 
  20.       context.Response.Write("自定义模块"); 
  21.      } 
  22.  
  23.      void Application_EndRequest(Object source,EventArgs e) 
  24.      { 
  25.       HttpApplication application=(HttpApplication)source; 
  26.       HttpContext context=application.Context; 
  27.       context.Response.Write("自定义模块"); 
  28.      } 
  29.  
  30. } 
  31. /* 
  32. * 在配置文件中配置 
  33. *<system.web> 
  34. *<httpModule> 
  35. *<add  name="HttpModule" type="HttpModule"/>  
  36. *</httpModule> 
  37. *</system.web> 
  38. */