What is the Global.asax used for?

The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

What is global.asax in ASP.NET? Application_start, Session_start?

The global.asax file is used to add application level logic & processing. Note that the global.asax does not handle any UI related processing, nor does it process individual page level requests. It basically controls the following events…
Application_Start
Application_End
Session_Start
Session_End

Note that in Visual Studio 2003 automatically creates this file for every web application, but in Visual Studio 2005, this file has to be added to the web project specifically.

Code in the global.asax is compiled when the web appication is built for the first time. The application level code and variables may be declared in Application_Start. Similarly, session level code & variables may be declared in Session_Start event. Application level events are for the entire application, and may be used for any user, while Session level events are user specific for a length of a session.

What is the role of global.asax?

Store global information about the application.

What file do you use to handle Session and Application events?

The global.asax file handles Session and Application events.

What are the major events in Global.Asax file?

  • Application_Init
  • Application Disposed
  • Application Error
  • Application Start
  • Application End
  • Application_BeginRequest
  • Application_EndRequest
  • Session Start
  • Session End
  • Application_AuthorizationRequest

List the event handlers that can be included in Global.asax.

  • Application start and end event handlers
  • Session start and end event handlers
  • Per-request event handlers
  • Non-deterministic event handlers

Steps to Get Visitors Count in ASP.NET?

Create Global.asax File:

  • Inside the void Application_Start()
  • Enter code as

Application["VC"]=0;

  • and Then Enter the Code inside the Session_Start() as

Application["VC"]=Convert.ToInt32(Application["VC"])+1;