i

ASP.Net A Complete Guide

Using the Global.asax File

It allows us to write an application-level event. Those events include application starts, a session ends, an application error occurring.

Global.asax file is located in a root directory of the application.

Example:

The code contains in this file is executed on the app-level or the session-level.

All the events available from that we have two groups of event that will get triggered

1. Events those will get triggered for every request

2. Events those will not get triggered for every request

Methods corresponding to events that fire on each request

Event Name

Description

Application_AuthenticateRequest       

Get called before the user credentials are authenticated.

Application_AuthorizeRequest()

Get called on successful authentication of the user's credentials. 

Application_BeginRequest()

Get called when there is a request for the web application.

Application_ResolveRequestCache()

Get called on successful completion of an authorization request.

Application_AcquireRequestState()

Get called just before the session state is retrieved for the current request.

Application_PreRequestHandlerExecute()

Get called before the page framework begins before executing an event handler to handle the request.

Application_PostRequestHandlerExecute()

Get called after HTTP handler has executed the request.

Application_ReleaseRequestState()

Get called before current state information kept in the session collection is serialized.

Application_UpdateRequestCache()

Get called before data is added to the output cache of the page.

Application_EndRequest()

Get called at the end of each request

 

Methods corresponding to events that do not fire on each request

 

Event Name

Description

Application_Start()

Get called when the first resource is requested from the server.

Session_Start()

Get called when the session starts new user requesting a page.

Application_Error()

Get called when an exception occurs.

Session_End()

Get called when the user session ends.

Application_End()

Get called when the application ends.

Application_Disposed()

Get called when the application is destroyed.