The Global.asax file is called as the ASP.NET application file, which contains the events related to Application and Session level
The file will be positioned in the root level of the Web Application.
Adding this file to the application is not mandatory, if you want to handle the Application events or session events then you can use the file
The following are the events available in the file,
// Triggered when the application starts, the logs to the event handler, initializing singleton objects may be written here
// Called when any uncaught error happened in the application
How to add Global.asax file in the application
1) In the Visual Studio ASP.NET application (Web Forms & MVC) Right click on the Web Application project name (Root Level)
2) Click add "New Item"
3) Look for "Global Application Class" and click add
The file will be positioned in the root level of the Web Application.
Adding this file to the application is not mandatory, if you want to handle the Application events or session events then you can use the file
The following are the events available in the file,
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void
Application_AuthenticateRequest(object
sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
How to add Global.asax file in the application
1) In the Visual Studio ASP.NET application (Web Forms & MVC) Right click on the Web Application project name (Root Level)
2) Click add "New Item"
3) Look for "Global Application Class" and click add
Comments