zoukankan      html  css  js  c++  java
  • 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
    --===------------------------------------------===---
    */
  • 相关阅读:
    黄聪:dreamweaver jquery代码提示安装,DW JQ代码智能提示
    明明白白AOP(你没有理由不心领神会!)
    myeclipse安装svn插件的多种方式
    spring注解
    freemarker入门例子
    MyEclipse10 中的两种FreeMarker插件的安装与配置
    优秀程序员必备的10个技能
    p2psearcher无法连接到KAD网络或ed2k服务器的解决办法
    MyEclipse 8.6.1下载|MyEclipse 8下载|MyEclipse 8.6.1官网下载
    网络技术网站
  • 原文地址:https://www.cnblogs.com/flaaash/p/996989.html
Copyright © 2011-2022 走看看