您的位置:首页 > 理论基础 > 计算机网络

HttpApplication 事件

2008-09-02 22:45 826 查看

AcquireRequestState 当 ASP.NET 获取与当前请求关联的当前状态(如会话状态)时发生。

AuthenticateRequest 当安全模块已建立用户标识时发生。

AuthorizeRequest 当安全模块已验证用户授权时发生。

BeginRequest 在 ASP.NET 响应请求时作为 HTTP 执行管线链中的第一个事件发生。

Disposed 添加事件处理程序以侦听应用程序上的 Disposed 事件。

EndRequest 在 ASP.NET 响应请求时作为 HTTP 执行管线链中的最后一个事件发生。

Error 当引发未处理的异常时发生。

PostAcquireRequestState 在已获得与当前请求关联的请求状态(例如会话状态)时发生。

PostAuthenticateRequest 当安全模块已建立用户标识时发生。

PostAuthorizeRequest 在当前请求的用户已获授权时发生。

PostMapRequestHandler 在 ASP.NET 已将当前请求映射到相应的事件处理程序时发生。

PostReleaseRequestState 在 ASP.NET 已完成所有请求事件处理程序的执行并且请求状态数据已存储时发生。

PostRequestHandlerExecute 在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生。

PostResolveRequestCache 在 ASP.NET 跳过当前事件处理程序的执行并允许缓存模块满足来自缓存的请求时发生。

PostUpdateRequestCache 在 ASP.NET 完成了缓存模块的更新并存储了以下响应时发生,这些响应用于满足来自缓存的后续请求。

PreRequestHandlerExecute 恰好在 ASP.NET 开始执行事件处理程序(例如,某页或某个 XML Web service)前发生。

PreSendRequestContent 恰好在 ASP.NET 向客户端发送内容之前发生。

PreSendRequestHeaders 恰好在 ASP.NET 向客户端发送 HTTP 标头之前发生。

ReleaseRequestState 在 ASP.NET 执行完所有请求事件处理程序后发生。该事件将使状态模块保存当前状态数据。

ResolveRequestCache 当 ASP.NET 完成授权事件以使缓存模块从缓存中为请求提供服务时发生,从而跳过事件处理程序(例如某个页或 XML Web services)的执行。

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()

{

}

}

}

注:本文是网上转贴
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: