Major events in Global.Asax file?

The Global.asax file contains code for responding to application-level events raised by ASP.NET or by HttpModules. It is located in the root directory of an ASP.NET application. This file contains code that is executed in response to application-level and session-level events raised by ASP.NET or by HTTP modules.

The following are some of the important events in the Global.asax file:

  1. Application_Init : The Application_Init event is fired when an application initializes the first time.

  2. Application_Start : The Application_Start event is fired the first time when an application starts.

  3. Application_AuthorizeRequest: Fired when the security module has verified that a user can access resources.

  4. Application_ResolveRequestCache : Fired on successful completion of an authorization request.

  5. Application_Disposed: Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.

  6. Session_Start : The Session_Start event is fired the first time when a user’s session is started. This typically contains for session initialization logic code.

  7. Application_BeginRequest: The Application_BeginRequest event is fired each time a new request comes in

  8. Application_EndRequest : The last event fired for an application request.

  9. Application_AuthenticateRequest : The Application_AuthenticateRequest event indicates that a request is ready to be authenticated. If you are using Forms Authentication, this event can be used to check for the user's roles and rights.

  10. Application_Error : The Application_Error event is fired when an unhandled error occurs within the application.

  11. Session_End : The Session_End Event is fired whenever a single user Session ends or times out.

  12. Application_End : The Application_End event is last event of its kind that is fired when the application ends or times out. It typically contains application cleanup logic.

The Global.asax file is optional. If you do not define the file, the ASP.NET page framework assumes that you have not defined any application or session event handlers.