Is there a way to know when a user terminates a web app?
I want to capture some information when it is terminated and since they can just close the browser, not sure if there is a way to do this.
Is there a way to know when a user terminates a web app?
I want to capture some information when it is terminated and since they can just close the browser, not sure if there is a way to do this.
Short answer is no.
You must build your solution in such way you get all the necessary info you need from the user, while active.
Unless the info is “approximate time of the logoff”, you can ping and record the last time of the ping of that session, let’s say, every 60 secs. But it creates an overhead when hundreds of users are online.
We don’t need to ping sessions to do that
The web framework provides control over how long a Session lasts after the user closes the tab with the WebApplication.SessionTimeout property.
When the user closes the browser tab or window, after the time designated by SessionTimeout, the WebSession.Closing event is raised. This event can be used to log the “approximate time of logoff” without adding any additional pinging or timers.
John, it is important to note that the web application does not actually terminate when the user leaves. The Xojo app is the web server, as we talked about in your other thread regarding a scheduled task. The App.Closing event will only occur if you are shutting down the entire app from the Xojo Cloud control panel.
Tim, your help is amazing. I really appreciate your response and I do recall your response in the prior thread. Have a great day and thank you.
The problem is, when you have a SessionTimeout of 30min, and you kill the browser after 2 minutes, unless something changed, your system will record that you were online idle for 30 minutes instead of 2 minutes.
If you know what the SessionTimeout is, you can subtract that from the time in the Closing event to know a little bit closer to roughly when we lost the browser.
My session timeout is set for 2 minutes and simply brings up a screen that they have to click or it terminates the session, so this will work in my case, but I see your point about long session.timeouts
Let’s suppose we have a session timeout set as 10 minutes, enough time to close the computer lid and move to the cafeteria, open the lid and continue the work without losing the session. But today, you opened the app, worked for 2 minutes and closed the lid and left. How long was the real session? I do expect the system recording 12 minutes instead of getting the time of the last heartbeat of such session.
You can use the Session’s UserDisconnected event and set a dateTime value store it to the session and then on the session’s closing event check how long ago this was by comparing the current datetime.now with the stored value.
Great! So there are ways to calculate the different bits one may be interested in. Are we missing any?
If you can get some spare time, would you mind to create a simple PoC? Just out of curiosity. And test using the scenario I described above (suspend the computer beyond the timeout threshold)? I’m not sure about the behavior and the supposed detection.