HttpApplication 事件

简介:
Public event AcquireRequestState 当 ASP.NET 获取与当前请求关联的当前状态(如会话状态)时发生。
Public event AuthenticateRequest 当安全模块已建立用户标识时发生。
Public event AuthorizeRequest 当安全模块已验证用户授权时发生。
Public event BeginRequest 在 ASP.NET 响应请求时作为 HTTP 执行管线链中的第一个事件发生。
Public event Disposed 添加事件处理程序以侦听应用程序上的 Disposed 事件。
Public event EndRequest 在 ASP.NET 响应请求时作为 HTTP 执行管线链中的最后一个事件发生。
Public event Error 当引发未处理的异常时发生。
Public event PostAcquireRequestState 在已获得与当前请求关联的请求状态(例如会话状态)时发生。
Public event PostAuthenticateRequest 当安全模块已建立用户标识时发生。
Public event PostAuthorizeRequest 在当前请求的用户已获授权时发生。
Public event PostMapRequestHandler 在 ASP.NET 已将当前请求映射到相应的事件处理程序时发生。
Public event PostReleaseRequestState 在 ASP.NET 已完成所有请求事件处理程序的执行并且请求状态数据已存储时发生。
Public event PostRequestHandlerExecute 在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生。
Public event PostResolveRequestCache 在 ASP.NET 跳过当前事件处理程序的执行并允许缓存模块满足来自缓存的请求时发生。
Public event PostUpdateRequestCache 在 ASP.NET 完成了缓存模块的更新并存储了以下响应时发生,这些响应用于满足来自缓存的后续请求。
Public event PreRequestHandlerExecute 恰好在 ASP.NET 开始执行事件处理程序(例如,某页或某个 XML Web service)前发生。
Public event PreSendRequestContent 恰好在 ASP.NET 向客户端发送内容之前发生。
Public event PreSendRequestHeaders 恰好在 ASP.NET 向客户端发送 HTTP 标头之前发生。
Public event ReleaseRequestState 在 ASP.NET 执行完所有请求事件处理程序后发生。该事件将使状态模块保存当前状态数据。
Public event ResolveRequestCache 当 ASP.NET 完成授权事件以使缓存模块从缓存中为请求提供服务时发生,从而跳过事件处理程序(例如某个页或 XML Web services)的执行。
Public event UpdateRequestCache 当 ASP.NET 执行完事件处理程序以使缓存模块存储将用于从缓存为后续请求提供服务的响应时发生。

 

Http Request在整个HttpModule中的生命周期图:

 Http Request开始
|
    HttpModule
   |
  HttpModule.BeginRequest()
|
   HttpModule.AuthenticateRequest()
|
   HttpModule.AuthorizeRequest()
|
HttpModule.ResolveRequestCache()
|
 建立HttpHandler控制点
|
   接着处理(HttpHandler已经建立,此后Session可用)
|
HttpModule.AcquireRequestState()
|
   HttpModule.PreRequestHandlerExecute()
|
进入HttpHandler处理HttpRequest
|
 HttpHandler.ProcessRequest()
|
返回到HttpModule接着处理(HttpHandler生命周期结束,Session失效)
|
   HttpModule.PostRequestHandlerExecute()
|
   HttpModule.ReleaseRequestState()
|
   HttpModule.UpdateRequestCache()
|
 HttpModule.EndRequest()
|
   HttpModule.PreSendRequestHeaders()
|
   HttpModule.PreSendRequestContent()
|
 将处理后的数据返回客户端
|
整个Http Request处理结束

示例:

using System;
using System.IO;
using System.Web;
using System.Xml;
using System.Data;
using System.Threading;
using System.Diagnostics;

namespace AbcMis.Framework.OUP.Passport
{
    class AuthenticateModule:System.Web.IHttpModule
    {
        public void Init(HttpApplication application)
        {
            application.BeginRequest += (new EventHandler(this.Application_BeginRequest));
            application.EndRequest += (new EventHandler(this.Application_EndRequest));
            application.PreRequestHandlerExecute += (new EventHandler(this.Application_PreRequestHandlerExecute));
            application.PostRequestHandlerExecute += (new EventHandler(this.Application_PostRequestHandlerExecute));
            application.ReleaseRequestState += (new EventHandler(this.Application_ReleaseRequestState));
            application.AcquireRequestState += (new EventHandler(this.Application_AcquireRequestState));
            application.AuthenticateRequest += (new EventHandler(this.Application_AuthenticateRequest));
            application.AuthorizeRequest += (new EventHandler(this.Application_AuthorizeRequest));
            application.ResolveRequestCache += (new EventHandler(this.Application_ResolveRequestCache));
            application.PreSendRequestHeaders += (new EventHandler(this.Application_PreSendRequestHeaders));
            application.PreSendRequestContent += (new EventHandler(this.Application_PreSendRequestContent));
        }

        private void Application_PreRequestHandlerExecute(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;
            string UserGuid = (string)context.Session["UserGuid"];
            context.Response.Write("Application_PreRequestHandlerExecute"+UserGuid+"<br>");
        }

        private void Application_BeginRequest(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_BeginRequest<br>");
        }

        private void Application_EndRequest(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_EndRequest<br>");

        }

        private void Application_PostRequestHandlerExecute(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_PostRequestHandlerExecute<br>");

        }

        private void Application_ReleaseRequestState(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_ReleaseRequestState<br>");

        }

        private void Application_UpdateRequestCache(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_UpdateRequestCache<br>");

        }

        private void Application_AuthenticateRequest(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_AuthenticateRequest<br>");

        }

        private void Application_AuthorizeRequest(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_AuthorizeRequest<br>");

        }

        private void Application_ResolveRequestCache(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_ResolveRequestCache<br>");

        }

        private void Application_AcquireRequestState(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_AcquireRequestState<br>");

        }

        private void Application_PreSendRequestHeaders(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_PreSendRequestHeaders<br>");

        }

        private void Application_PreSendRequestContent(Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication)source;
            HttpContext context = application.Context;

            context.Response.Write("Application_PreSendRequestContent<br>");

        }
        public void Dispose()
        {
        }

    }

}

 

注:本文是网上转贴

 

转载请注明出处[ http://samlin.cnblogs.com/] 
作者赞赏
 


刚做的招标网: 八爪鱼招标网 请大家多意见
标签:  HttpApplication

本文转自Sam Lin博客博客园博客,原文链接:http://www.cnblogs.com/samlin/archive/2008/09/02/HttpApplication-Event.html,如需转载请自行联系原作者
目录
相关文章
|
Unix 关系型数据库 Linux
技术笔记:linux学习心得
技术笔记:linux学习心得
110 0
|
存储 安全 Linux
句柄是什么?一文带你了解!
今天又学习了一个装X概念——句柄,看字面意思,感觉跟某种器具有关,但实际上,这个词可不是用来打造家居用品的。
1859 0
|
JavaScript 前端开发
css:隐藏input file标签并触发点击上传文件事件
css:隐藏input file标签并触发点击上传文件事件
772 0
css:隐藏input file标签并触发点击上传文件事件
|
JavaScript
【异常】$ is not defined (已解决)
$ is not defined (已解决),F12调试页面Console错误提示
262 0
Uncaught DOMException: Blocked a frame with origin "http://localhost:8000" from accessing a cross-origin frame.
Uncaught DOMException: Blocked a frame with origin "http://localhost:8000" from accessing a cross-origin frame.
1921 0
|
编解码 C#
C#(三十八)之StreamWriter StreamWriter使用方法及与FileStream类的区别
本篇内容记录了StreamReader类的属性和方法、StreamWriter类的属性和方法等
508 0
C#(三十八)之StreamWriter StreamWriter使用方法及与FileStream类的区别
|
开发框架 中间件 .NET
ASP.NETCore编程实现基本认证
在HTTP中,HTTP基本认证(Basic Authentication)是一种允许浏览器或其他客户端程序使用(用户名,口令)请求资源的身份验证方式,不要求cookie,session identifier、login page等标记或载体。 所有浏览器据支持HTTP基本认证协议 基本身证原理不保证传输凭证的安全性,仅被based64编码,并没有encrypted或者hashed,一般部署在互信的内网,在公网上应用BA协议通常与https结合。
ASP.NETCore编程实现基本认证
|
网络协议 中间件
HttpClientFactory-向外请求的最佳
它的组件包是Microsoft.Extensions.Http 复原HttpClient带来的问题
370 0
|
JavaScript 前端开发 .NET
一起谈.NET技术,ASP.NET前台代码绑定后台变量方法总结
  经常会碰到在前台代码中要使用(或绑定)后台代码中变量值的问题。一般有和两种方式,这里简单总结一下。如有错误或异议之处,敬请各位指教。   一方面,这里所讲的前台即通常的.aspx文件,后台指的是与aspx相关联的CodeBehind,文件后缀名为.aspx.cs;另一方面,这里的绑定是指用户发出访问某一页面指令后,服务器端在执行过程中就已经将前台代码进行了赋值,而后生成html格式回传客户端显示,而并非已经显示到客户端后,然后通过其他方法(如ajax)去服务器端获取相应变量。
1479 0