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