To count the number of Active Session(s) we have to handle three events of Global.asax.
First the Application_Start event will be fired after that Session_Start and then Session_End.
The Global.asax file is used to track the number of active sessions. Whenever a new session begins, the Session Start event is raised and the SessionCount variable is incremented by one. When a session ends, the Session End event is raised and the SessionCount variable is decremented by one.
The SessionCount variable is stored in the Application state, which contains items that are shared among all users of a web application.
Multiple users could potentially access the same item in Application state at the same time so we must lock and unlock the Application object.
The Session Count can be shown in the Web Page with a Label Control.