The subject says it all. Is there any way to determine
how many clients are attached to a web application and
what session data is in use for each client?
Hi Walt,
This isn't too hard to do. What is hard is using it safely once you've got
it setup. With this, all users have access to all other users' data. Also,
updates to the data could occur at any time, including multiple
simultaneous access to the same data. With one session per user, this isn't
much of a problem. With everyone accessing each other's data, it could
cause problems.
Here is one way to do this. This method puts a collection object into the
application object and adds each session to the collection.
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim colAllSessions As New Collection
Application.Add("AllSessions", colAllSessions)
Dim colOldSessions As New Collection
Application.Add("OldSessions", colOldSessions)
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
CType(Application("AllSessions"), Collection).Add(Session,
Session.SessionID)
Session("test") = "hello " & Session.SessionID
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
CType(Application("OldSessions"), Collection).Add(Session.SessionID,
Session.SessionID)
CType(Application("AllSessions"),
Collection).Remove(Session.SessionID)
End Sub
---
This can be tested with a test page with this code-behind:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(Session.SessionID)
Response.Write("<hr>")
Dim i As Long
For i = 1 To CType(Application("AllSessions"), Collection).Count
Response.Write(CType(CType(Application("AllSessions"),
Collection).Item(i), SessionState.HttpSessionState).SessionID & "<br>")
Next
Response.Write("<hr>")
For i = 1 To CType(Application("OldSessions"), Collection).Count
Response.Write(CType(Application("OldSessions"),
Collection).Item(i) & "<br>")
Next
Response.Write("<hr>")
End Sub
---
Does this answer your question?
Thank you, Mike
Microsoft, ASP.NET Support Professional
Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer?s security.
This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
> Content-Class: urn:content-classes:message
> From: "Walt" <lord@brodart.com>
[quoted text clipped - 13 lines]
> Path: cpmsftngxa06.phx.gbl
> Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.caching:1468
> NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.caching
>
> The subject says it all. Is there any way to determine
> how many clients are attached to a web application and
> what session data is in use for each client?