How to show number and names of users logged in into application

Within a maintenance part of our application, we have to show the number and names of the users logged in into our application (comparable to the information as present on the Mendix deployment web-site under 'Show Logged in Users') I thought the ActiveSessions page within the Administration module would do this, but this list is always empty..... How to achieve this?  
3 answers

The Active Sessions are available with the custom setting PersistentSessions set to true


The list is empty because it attempts to retrieve sessions from database. Unless, as Chris pointed out, you actually persist your sessions, this list will always be empty.

You can resolve your issue by using persistent sessions, though I am not certain this will always properly reflect the sessions that are actively logged in at a given time.

Alternately, you could add a bit of custom code to your login process that associates a session to a singleton upon login, which you can call to give you the list of sessions in memory. 


If you're not afraid of a little Java, create a Java action and call this:


It will get you a list of sessions, create a non-persistent object for each one and show it in a grid.


I tried it and it does show all sessions. You might end up with some abandoned sessions when the user closed the browser but I guess the Mendix cloud function has the same limitation. I used the following code to get all user names of the active sessions:


	for (ISession session: Core.getActiveSessions()) {
		String userName = session.getUser().getName();


Is this sufficient for you to solve your issue?