Role of the global. asax file:
1. Define application-level and session-level variables, objects, and data;
2. Events defined in Application Based on application and session;
Define application and session-level variables:
Use the application object to define the variables in the application range, and use the session object to define the variables in the session range.
// Set Variables
Application ( " Myapplicationscopevar " ) = " Myvalue " ;
Session ( " Mysessionscopevar " ) = " Myvalue " ; // Get variable
Myvalue = Application ( " Myapplicationscopevar " );
Myvalue = Session ( " Mysessionscopevar " );
Static object. The COM/COM + component can use the object declaration in global. asax, and its scope is application or session.
Pipeline specifies that the specified object or component is in the current httpapplication instance and is not shared.
Application Event:
Triggered when application_start-application is started;
Triggered when application_end-application is stopped;
Application_beginrequest-triggered when a request is received
Application_endrequest-end request triggering
Application_authenticationrequest-triggered when an authentication request is received
Application_error-triggered when an error occurs
Session event:
Session_start-triggered when the client creates a session;
Session_end-triggered when the client ends the session;
Scripts can still be used in global. asax to define variables and events; 01 < Script Language = " VB " Runat = " Server " >
02
03
04 ' Application Start up code goes here
05 Sub Application_onstart ()
06 Application ( " Myapplicationscopevar " ) = " Myvalue"
07 Session ( " Myapplicationscopevar " ) = " Myvalue"
08 End sub
09
10 ' Application clean up code goes here
11 Sub Application_onend ()
12 End sub
13
14 ' Session start up code goes here
15 Sub Session_onstart ()
16 End sub
17
18 ' Session clean up code goes here
19 Sub Session_onend ()
20 End sub
21
22
23 </ Script >
When the global. asax file is changed, ASP. NET detects the change of this file. After all the existing requests are processed
Application_onend () event, and then restart the application.
The process above resets the entire site and clears session and other stored information. When a new request arrives, Asp. net will re-compile global. the asax file triggers the application_onend () event.
Therefore, if you want to change the global. asax file, you should do it when the site is busy.
about global. notes for the asax file:
global. the asax file exists in the root directory of the site.
each site can have only one global. asax file;
when the first request to Site Resources, Asp.net will. the asax file is compiled into a class (inherited from the httpapplication class);
global. the asax file is self-configured for security purposes and cannot be accessed from external URLs.
reference:
inside ASP. net
scott worley
Publisher: New Riders publishing
first edition November 15,200 1
ISBN: 0-7357-1135-6,730 pages