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
    --===------------------------------------------===---
    */
  • 相关阅读:
    选择时区的命令tzselect
    Linux就这个范儿 第16章 谁都可以从头再来--从头开始编译一套Linux系统 nsswitch.conf配置文件
    centos mysql 实战 第一节课 安全加固 mysql安装
    linux mknod命令解析
    keepalived对nginx高可用演练脚本
    install 命令用法详解
    基于 HTML5 的 WebGL 自定义 3D 摄像头监控模型
    基于 HTML5 结合工业互联网的智能飞机控制
    基于HTML5 的互联网+地铁行业
    基于 HTML5 结合互联网+ 的 3D 隧道
  • 原文地址:https://www.cnblogs.com/flaaash/p/996989.html
Copyright © 2011-2022 走看看