Introduction to the Global. asax File
• Stored in applicationsProgramIn the root directory
• Define application boundaries
• Initialize application-level or session-level variables
• Connect to the database
• Send cookie
Global. asax event
Event |
Trigger time |
Application_onstart |
This is triggered when the first ASP. NET page of the current application directory (or its subdirectory) is called. |
Application_onend |
Triggered when the last session of the application ends. In addition, it is triggered when you use the Internet Service Manager Management Unit to stop web applications. |
Application_onbeginrequest |
It is triggered at the beginning of each page request (theoretically, when the page is loaded or refreshed. |
Application_onendrequest |
It is triggered at the end of each page request (that is, every time the page is executed in the browser. |
Session_onstart |
It is triggered at the beginning of each new session. |
Session_onend |
It is triggered at the end of the session. (For more information about how to end a session, see session object ). |
Httpapplication class
• Define methods, attributes, and events common to all application objects in ASP. NET Applications
• This class is the base class of the application defined by the user in the global. asax file.
• Such instances are created in the ASP. NET infrastructure, rather than directly created by users.
• An instance is used to process multiple requests within its lifetime, but it can only process one request at a time.
Httpapplicationstate class and application instance
• The httpapplicationstate class enables global information sharing between multiple sessions and requests in ASP. NET Applications
• The Application Object obtains the current state of the application.
• The application object can be obtained through attributes of the httpapplication class or page class.