zoukankan      html  css  js  c++  java
  • 如何确定asp.net请求生命周期的当前处理事件

    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"); } } }
  • 相关阅读:
    17.Letter Combinations of a Phone Number(递归生成序列)
    BZOJ 4052 Magical GCD
    管理学的入门经典书籍,初级管理学书籍推荐
    关于经营战略的书,商业战略书籍推荐
    如何成为一名合格的销售管理者?
    能帮你提升沟通能力的书籍推荐
    提升领导力心得体会
    口才和说服力的书籍推荐,学会说服别人你需要看这本书
    团队管理的书籍推荐 ,这些书教你如何打造团队
    管理学必读书单推荐:这些书教你学好经营管理知识
  • 原文地址:https://www.cnblogs.com/mibing/p/7657067.html
Copyright © 2011-2022 走看看