Meanings of methods in global. asax. CS

Source: Internet
Author: User
Tags website performance
Today, I would like to explain the meaning of the methods in global. asax. cs. You are welcome to speak! Put the content related to the request together with the other five.

Application_init: Executed during initialization of each httpapplication instance.
Application_disposed: Executed before each httpapplication instance is destroyed.
Application_error: All errors that are not processed will result in execution of this method.
Remember: init-> disposed-> Error

Application_start: InProgramIt is executed during initialization. The Web application is executed once in its lifecycle (Automatic Restart is another lifecycle). Only public information such as httpapplicationstate can be put here.
Application_end: When the application ends, it is executed after the last httpapplication is destroyed. It corresponds to application_start and is only executed once throughout the lifecycle.
Similarly, start-> end

Next let's take a look at the request. First, let's look at the corresponding event execution sequence:
1. beginrequest [request]
2. authenticaterequest [authentication]
3. authorizerequest [authorization]
4. resolverequestcache [resolution request cache]
5. acquirerequeststate [obtain Request status]
6. prerequesthandlerexecute [pre-request processing]
7. postrequesthandlerexecute [Send request processing]
8. releaserequeststate [Release Request status]
9. updaterequestcache [refresh request cache]
10. endrequest [Stop request]

There are two more:

1. presendrequestheaders [Send request header]
2. presendrequestcontent [sent content]

The order of these two events is uncertain. According to msdn, they may occur at any time. The following explains the meaning of corresponding event handling methods in global. asax. CS in this order.

Application_beginrequest : Beginrequest is the first event triggered when a request is received. This method is the first event to be executed.
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 : When ASP. NET completes the authorization event so that the cache module can provide services for requests from the cache, the execution of the Processing Program (page or WebService) is skipped. This can improve the website performance. This event can also be used to determine whether the body is obtained from the cache.
Application_acquirerequeststate : When ASP. net to obtain the current State associated with the current request (such as session). (It's really a bad mouth. It's written on msdn. I can't think of any good sentences ).
Application_prerequesthandlerexecute : It is executed before ASP. NET sends the request to the processing program object (page or WebService. At this time, the session can be used.
Application_postrequesthandlerexecute : It is executed after the processing program object (page or WebService) is completed.
Application_releaserequeststate : Execute all request processing programs in ASP. NET. The releaserequeststate event saves the current state data.
Application_updaterequestcache : After ASP. NET executes the processing program, it updates the response cache for subsequent requests.
Application_endrequest : Same as above, endrequest is the last event triggered in response to the request. This method is naturally the last one to be executed.

Besides, these two unordered
Application_presendrequestheaders : Executed before sending the HTTP header to the client.
Application_presendrequestcontent : Run the command before sending the HTTP body to the client.

Finally, there are two sessions. This is simple.

Session_start: Run when the session starts.
Session_end: Executed when the session ends or expires.

In fact, this is not only available in global. asax. CS. Ihttpmodule The event exposed by the interface class can be put here in this way. The premise is that there is a declaration in global. asax (or web. config. In addition, global. there are still many patterns in asax, but I have not sorted them out, but it is actually very simple (more importantly, it is not useful in many cases). There are detailed descriptions in msdn, you can check that I think the most useful thing is to mark the object.

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.