2

I am looking for an easy way to programatically find out if currently any user sessions are open on my IIS (7, 7.5, 8) web application. I don't want to count logins and logouts, just check if there is more than one user active ... A similar question was asked for PHP: Find Number of Open Sessions and there are a number of other issues around but all are based on PHP. Unfortunatelsy that doesn't help me in my vb.net environment.

I am aware that the sessions will be open and counted until the session timeout is reached, even if the users are not longer using the application.

I need the information from within an aspx.vb (is this user the only onw who is currently working on the application) or from a window console application (is there really only one user currently using my web application).

Any ideas? Thanks

Community
  • 1
  • 1
Herbert
  • 151
  • 2
  • 12

1 Answers1

0

You can do this with a global.asax file something like this:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    Application.Lock()
    Application("User_Count") = 0
    Application.UnLock()
End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    Application.Lock()
    Application("User_Count") = Integer.Parse(Application("User_Count")) + 1
    Application.UnLock()
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    Application.Lock()
    Application("User_Count") = Integer.Parse(Application("User_Count")) - 1
    Application.UnLock()
End Sub

Then Application("User_Count") will have the number of non-expired sessions. To access from a console application you might need to create a service on your site that you can call and retrieve the value.

theduck
  • 2,589
  • 13
  • 17
  • 23