Today, a colleague asked me to explain.Global. asax. CSThe meaning of the method in, sort it out, and send it to you.
AndRequestPut the relevant information together. Let's talk about other5.
Application_init: In eachHttpapplicationIt is executed during instance initialization.
Application_disposed: In eachHttpapplicationRun the command before the instance is destroyed.
Application_error: All errors that are not processed will result in execution of this method.
Application_start: InProgramIt is executed during initialization. InWebThe application is executed once in its life cycle (Automatic Restart is another life cycle). Only public information can be put here, suchHttpapplicationstate.
Application_end: When the application endsHttpapplicationRun the command after destruction. CorrespondingApplication_startAnd only once in the entire lifecycle.
Next let's take a lookRequestFirst, let's look at the event execution sequence:
1.Beginrequest
2.Authenticaterequest
3.Authorizerequest
4.Resolverequestcache
5.Acquirerequeststate
6.Prerequesthandlerexecute
7.Postrequesthandlerexecute
8.Releaserequeststate
9.Updaterequestcache
10.Endrequest
There are two more:
1.Presendrequestheaders
2.Presendrequestcontent
The order of the two events is uncertain.MsdnThey can happen at any time. Next we will explain them in this OrderGlobal. asax. CSThe meaning of the corresponding event processing method.
Application_beginrequest:BeginrequestYesRequestWhen the first event is triggered, this method is naturally the first execution.
Application_authenticaterequest: Run the Security Module after the current user ID is set up.
Application_authorizerequest: Executed when the security module has verified the authorization of the current user.
Application_resolverequestcache: WhenASP. NETWhen the authorization event is completed so that the cache module provides services for requests from the cache, the handler is skipped (Page ORWebService. This can improve the performance of the website. This event can also be used to determine whether the body is fromCache.
Application_acquirerequeststate: WhenASP. NETObtain the current status associated with the current request (for exampleSession,MsdnI can't think of any good sentences ).
Application_prerequesthandlerexecute: WhenASP. NETThe request will be sent to the processing program object (page orWebService. At this time,SessionYou can use it.
Application_postrequesthandlerexecute:When the handler object (page orWebService.
Application_releaserequeststate: InASP. NETAfter all request processing programs are executed.ReleaserequeststateThe event will save the current status data.
Application_updaterequestcache: InASP. NETAfter the processing program is executed, it is executed when the response cache is updated for subsequent requests.
Application_endrequest: Same as above,EndrequestIs in responseRequestWhen the last event is triggered, this method is naturally the last execution.
Besides, these two unordered
Application_presendrequestheaders: Send to clientHTTPBefore the header.
Application_presendrequestcontent: Send to clientHTTPRun the command before the body.
There are twoSessionThis is simple.
Session_start: Run when the session starts.
Session_end: Executed when the session ends or expires.
In fact, global. asax. CS not only supports this, other events exposed by classes that implement the ihttpmodule interface can be put here. The premise is that there is a declaration in global. asax (or Web. config . In addition, global. asax can also have a lot of tricks, but it is actually very simple if I haven't sorted it out (more importantly, it is usually not useful ), msdn provides a detailed description. You can check whether the Object mark is the most useful one, ^ _ ^