HttpModule,ASP.NET中多个HttpModule的处理


using  System;
using  System.Web;

namespace  xumh
{
    
///   <summary>
    
///  多个HttpModule的应用示例:
    
///  web.config文件中HttpModules里面先Add哪一个他就先执行,按add的顺序分别执行
    
///  多个HttpModule要过滤的事件会分别处理
    
///   </summary>
     public   class  multiHttpModule : IHttpModule
    {
        
public   void  Dispose()
        {
            
throw   new  NotImplementedException();
        }

        
public   void  Init(HttpApplication context)
        {
// 重新定义ASP.NET的事件处理程序
            context.BeginRequest  +=   new  EventHandler(myBeginRequest);
            context.EndRequest 
+=   new  EventHandler(myEndRequest);
            context.PreRequestHandlerExecute 
+=   new  EventHandler(myPreRequestHandlerExecute);
            context.PostRequestHandlerExecute 
+=   new  EventHandler(myPostRequestHandlerExecute);
            context.ReleaseRequestState 
+=   new  EventHandler(myReleaseRequestState);
            context.AcquireRequestState 
+=   new  EventHandler(myAcquireRequestState);
            context.AuthenticateRequest 
+=   new  EventHandler(myAuthenticateRequest);
            context.AuthorizeRequest 
+=   new  EventHandler(myAuthorizeRequest);
            context.ResolveRequestCache 
+=   new  EventHandler(myResolveRequestCache);
            context.PreSendRequestHeaders 
+=   new  EventHandler(myPreSendRequestHeaders);
            context.PreSendRequestContent 
+=   new  EventHandler(myPreSendRequestContent);
        
        }

        
void  myPreSendRequestContent( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myPreSendRequestContent<br/> " );
        }

        
void  myPreSendRequestHeaders( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myPreSendRequestHeaders<br/> " );
        }

        
void  myResolveRequestCache( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myResolveRequestCache<br/> " );
        }

        
void  myAuthorizeRequest( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" BeginRequest<br/> " );
        }

        
void  myAuthenticateRequest( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" BeginRequest<br/> " );
        }

        
void  myAcquireRequestState( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myAcquireRequestState<br/> " );
        }

        
void  myReleaseRequestState( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myReleaseRequestState<br/> " );
        }

        
void  myPostRequestHandlerExecute( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myPostRequestHandlerExecute<br/> " );
        }

        
void  myPreRequestHandlerExecute( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myPreRequestHandlerExecute<br/> " );
        }

        
void  myEndRequest( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" myEndRequest<br/> " );
        }

        
void  myBeginRequest( object  sender, EventArgs e)
        {
            HttpApplication app 
=  (HttpApplication)sender;
            HttpContext context 
=  app.Context;
            context.Response.Write(
" multiHttpModules:myBeginRequest<br/> " );
        }

    }
}
/* --===------------------------------------------===---
输出结果:
 testHttpModule:myBeginRequest
multiHttpModules:myBeginRequest
BeginRequest
BeginRequest
myResolveRequestCache
myAcquireRequestState
myPreRequestHandlerExecute

 
myPostRequestHandlerExecute
myReleaseRequestState
myEndRequest
myPreSendRequestHeaders
--===------------------------------------------===---
*/

转载于:https://www.cnblogs.com/flaaash/archive/2007/12/16/996989.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值