The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.
The global.asax file is used to add application level logic & processing. Note that the global.asax does not handle any UI related processing, nor does it process individual page level requests. It basically controls the following events…
Note that in Visual Studio 2003 automatically creates this file for every web application, but in Visual Studio 2005, this file has to be added to the web project specifically.
Code in the global.asax is compiled when the web appication is built for the first time. The application level code and variables may be declared in Application_Start. Similarly, session level code & variables may be declared in Session_Start event. Application level events are for the entire application, and may be used for any user, while Session level events are user specific for a length of a session.
Store global information about the application.
The global.asax file handles Session and Application events.
- Application Disposed
- Application Error
- Application Start
- Application End
- Session Start
- Session End
- Application start and end event handlers
- Session start and end event handlers
- Per-request event handlers
- Non-deterministic event handlers
Create Global.asax File:
- Inside the void Application_Start()
- Enter code as
- and Then Enter the Code inside the Session_Start() as