The Global.asax file is an optional file used to declare application and session level events for an ASP.NET application. It is also known as the ASP.NET application file. The Global.asax file is used to handle application-level events and session-level events raised by ASP.NET or by HttpModules.
Example:
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application end
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends
}