分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

如何确定asp.net请求生命周期的当前处理事件

发布时间:2023-09-06 01:17责任编辑:郭大石关键词:暂无标签

1 首先在全局应用程序里面添加如下代码

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Security;using System.Web.SessionState;namespace Events{ ???public class Global : System.Web.HttpApplication ???{ ???????public Global() ???????{ ???????????BeginRequest += HandleEvent; ???????????EndRequest += HandleEvent; ???????????AcquireRequestState += HandleEvent; ???????????PostAcquireRequestState += HandleEvent; ???????} ???????private void HandleEvent(object sender, EventArgs e) ???????{ ???????????//httpContext类用于访问所有有关应用程序,所处理的请求以及正在构建的请求的信息,并且它的属性currentNotification定义了HttpApplication
事件的子集 ???????????string eventName = "<Unknown>"; ???????????switch (Context.CurrentNotification) ???????????{ ???????????????case RequestNotification.BeginRequest: ???????????????case RequestNotification.EndRequest: ???????????????????eventName = Context.CurrentNotification.ToString(); ???????????????????break; ???????????????case RequestNotification.AuthenticateRequest: ???????????????????break; ???????????????case RequestNotification.AuthorizeRequest: ???????????????????break; ???????????????case RequestNotification.ResolveRequestCache: ???????????????????break; ???????????????case RequestNotification.MapRequestHandler: ???????????????????break; ???????????????????//当asp.net fromework需要与请求关联的状态时,将触发改事件 ???????????????case RequestNotification.AcquireRequestState: ???????????????????if (Context.IsPostNotification) ???????????????????{ ???????????????????????eventName = "PostAcquireRequestState"; ???????????????????} ???????????????????else ???????????????????{ ???????????????????????eventName = "AcquireRequestState"; ???????????????????} ???????????????????break; ???????????????case RequestNotification.PreExecuteRequestHandler: ???????????????????break; ???????????????case RequestNotification.ExecuteRequestHandler: ???????????????????break; ???????????????case RequestNotification.ReleaseRequestState: ???????????????????break; ???????????????case RequestNotification.UpdateRequestCache: ???????????????????break; ???????????????case RequestNotification.LogRequest: ???????????????????break; ???????????????case RequestNotification.SendResponse: ???????????????????break; ???????????????default: ???????????????????break; ???????????} ???????????EventCollection.Add(EventSource.Application, eventName); ???????} ???????protected void Application_Start(object sender, EventArgs e) ???????{ ???????????EventCollection.Add(EventSource.Application, "Start"); ???????????Application["message"] = "Aplication Events"; ???????} ???????protected void Session_Start(object sender, EventArgs e) ???????{ ???????} ???????protected void Application_BeginRequest(object sender, EventArgs e) ???????{ ???????????//收到请求时触发的第一个事件 ???????????EventCollection.Add(EventSource.Application, "BeginRequest"); ???????????Response.Write(string.Format("request started at {0}", DateTime.Now.ToLongTimeString())); ???????} ???????protected void Application_EndRequest(object sender,EventArgs e) ???????{ ???????????EventCollection.Add(EventSource.Application, "EndRequest"); ???????} ???????protected void Application_AuthenticateRequest(object sender, EventArgs e) ???????{ ???????} ???????????????protected void Application_Error(object sender, EventArgs e) ???????{ ???????} ???????protected void Session_End(object sender, EventArgs e) ???????{ ???????} ???????protected void Application_End(object sender, EventArgs e) ???????{ ???????????EventCollection.Add(EventSource.Application,"End"); ???????} ????}}

如何确定asp.net请求生命周期的当前处理事件

原文地址:http://www.cnblogs.com/mibing/p/7657067.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved