Hi to all ,
can I check users who are online in the web application? I don’t like writing to the db when logging in.
Thanks for the help
Hi Frantisek,
You can check the amount of WebSessions, using WebApplication.SessionCount.
If you want to have a list of unique logged users without a DB, you can add a property (for example: LoggedUserId) to your Session class, with the logged user ID.
Var activeUsers As New Dictionary
For Each activeSession As WebSession In App.Sessions
If activeSession.LoggedUserId > 0 Then
activeUsers.Value(activeSession.LoggedUserId) = True
End If
Next
Var loggedUsers As Integer = activeUsers.KeyCount
Just remember to fill the LoggedUserId as soon as the user logs in, and set it to 0 again when the user logs out.
Hi
This is a good idea, but if the user does not logout, he just closes the browser and the logout procedure does not take place.
The WebSession will expire eventually (180 seconds by default), and will disappear from that list.
https://documentation.xojo.com/api/web/webapplication.html#webapplication-sessiontimeout