There are two life cycles in an asp.net application
Request life cycle
Specific to every request which is received by the asp.net framework.Each request has its own request life cycle events.
Application life cycle
Begins when the application is started and ends when the application is stopped.Different application life cycle events are raised as the application executes.
Both of these events can be handled in the global application class.
Global application class in asp.net is defined in the file global.asax.cs file. This class contains event handlers which are fired
for the different stages of the application and request life cycle.
Following are the main application life cycle event handlers used in the global.asax
Application_Start() called when the application starts.This method is used for implementing the application configuration.For example in MVC application it is used for defining the routes of the application.
Application_End() called just before the application stops.This is used to perform the cleanup activities such as releasing the system resources.
A new instance of the application class HttpApplication defined in the global.asax.cs is created to handle request which is received by ASP.NET.The event handlers defined by this instance is used handle the specific requests.
Following are some of the main request lifecycle events which can be handled in global.asax.cs class.
BeginRequest Trigerred for every new request.
AuthenticateRequest Used to idenify the user who made the request.
AuthorizeRequest Used to authorize the request.
AcquireRequestState Used to obtain data for the request.This also include the session state.
PreRequestHandlerExecute Executes before the request handler executes
PostRequestHandlerExecute Executes after the request executes
EndRequest Executes before the response is sent to the browser.
The events which are handled in the ASP.NET global application class can also be handled in HttpModules.Its better to use HttpModules to handle the events if we are handling lot of events.