How many users are using the site at a same time?

The article describes to come to know that, How many users are hitting the website at a same time.
  • 1957

How can we find the no. of users, using the same website at the same point of time?


The article provides the solution for the above problem.

For this I used Global.asax. In Global.asax, we find a lot of methods such as  Application_Start, Application_End, Session_Start, Session_End etc. 

Here, I used Application_Start and Session_Start method.

In Application_Start method, I declare a varaible of Aplication Type, like:

 

Private Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

    Application("User") = 0

End Sub

After declaring it, I am using Session_Start Method, like:

Private Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

    Dim count As Integer

    count = CType(Application("User"), Integer)

    count = count + 1

    Application("User") = count

End Sub

In this Session_Start method I declare a variable of integer type. I type cast the Application["User"] with "int" to store the value of Application["User"]  in variable count. After running the application, create a new session. Once  new session is created, Session_start method will be called up. On each and every call, the value of variable count will be increased by 1. By the help of this we can trap the total no. of users, hitting the site at a same part of time.

The number of total users will come on to the form. 

Code on Page_Load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    Response.Write(Application("User").ToString())

End Sub

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.