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

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

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