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

0
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?  
asked
3 answers
0

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

answered
0

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. 

answered
0

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

Core.getActiveSessions()

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

Edit:

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?

answered