How to determine the current processing event for the ASP. NET Request life cycle

Source: Internet
Author: User

1 First add the following code to the global application

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.SessionState;namespaceevents{ Public classGlobal:System.Web.HttpApplication { PublicGlobal () {beginrequest+=handleevent; EndRequest+=handleevent; AcquireRequestState+=handleevent; Postacquirerequeststate+=handleevent; }        Private voidHandleevent (Objectsender, EventArgs e) {            //The HttpContext class is used to access information about all applications, requests processed, and requests being built, and its properties currentnotification defined HttpApplication
Subset of Events stringEventName ="<Unknown>"; Switch(context.currentnotification) { Caserequestnotification.beginrequest: CaseRequestNotification.EndRequest:eventName=Context.CurrentNotification.ToString (); Break; Caserequestnotification.authenticaterequest: Break; Caserequestnotification.authorizerequest: Break; CaseRequestnotification.resolverequestcache: Break; CaseRequestnotification.maprequesthandler: Break; //A Change event is triggered when an ASP. NET Fromework needs to be associated with the requested State Caserequestnotification.acquirerequeststate:if(context.ispostnotification) {eventName="postacquirerequeststate"; } Else{eventName="AcquireRequestState"; } Break; CaseRequestnotification.preexecuterequesthandler: Break; CaseRequestnotification.executerequesthandler: Break; Caserequestnotification.releaserequeststate: Break; CaseRequestnotification.updaterequestcache: Break; Caserequestnotification.logrequest: Break; CaseRequestnotification.sendresponse: Break; default: Break; } eventcollection.add (Eventsource.application, eventName); } protected voidApplication_Start (Objectsender, EventArgs e) {Eventcollection.add (eventsource.application,"Start"); application["message"] ="aplication Events"; } protected voidSession_Start (Objectsender, EventArgs e) { } protected voidApplication_BeginRequest (Objectsender, EventArgs e) { //The first event triggered when a request is receivedEventcollection.add (Eventsource.application,"beginrequest"); Response.Write (string. Format ("request started at {0}", DateTime.Now.ToLongTimeString ())); } protected voidApplication_EndRequest (ObjectSender,eventargs e) {Eventcollection.add (eventsource.application,"EndRequest"); } protected voidApplication_AuthenticateRequest (Objectsender, EventArgs e) { } protected voidApplication_Error (Objectsender, EventArgs e) { } protected voidSession_End (Objectsender, EventArgs e) { } protected voidApplication_End (Objectsender, EventArgs e) {Eventcollection.add (eventsource.application,"End"); } }}

How to determine the current processing event for the ASP. NET Request life cycle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.