29 January 2013

Global.asax in Asp.Net

It is used to handle the application level events.  It is an option file and if there are any events written then it will be fired. If you want to share any information across the users then application level logic has to be written in this file. Because session will be per use and the global data which has to be shared across the server needs to written in Application_Start event. It will be fired at the first request to the server.

If you want to write any logic while application shutdown then Application_End event should be fired. 

Some times we may need to write the logic when new session starts. When user logged in then new session will be started and it will fire the Session_start and when session ends Session_End event will be fired. This will be shared only for that session.

If there is any error occur in the application then Application_Error event helps you to capture the error.
The Global.asax file consists of following events that can be handled using it:

1. Application_Start

2. Session_Start

3. Application_BeginRequest

4. Application_AuthenticateRequest

5. Application_Error

6. Session_End

7. Application_End