Hello,
I have an ASP.NET MVC C# application that users can log in to the system based on roles. I would like to limit the number of login sessions per user. Add event listener javascript to detect when the browser or current tab is closing and call the logout function
Any sample code on how to achieve the above tasks is much appreciated. Thanks in advance.
Yazhini MPPosted Dec 6, 2021, 6:24 AM
You could store the SessionID of a user in a database. On each login, store a combination of Unique username and SessionID into the database. In the masterpage you include the query to the database, to check wether the last login for the currently used username was from the same session. If not, abandon the session and redirect to the login page.The behaviour I posted should log out the second user. You may change the Session.Abandon to your desired behaviour.
Lakshna SPosted Dec 3, 2021, 11:18 AM
You could always implement the events in global.asax.
Implement Application_Start() to setup a System.Collections.Dictionary (or at your preference) and store that in the Application[] collection, when a user logsin, add the username. Remove from the collection in Session_End(). Remember to use the 'lock' keyword while working with the collection