any suggestion how to implement concurrent login
same user account cannot access from multiple browser. if user login from two browser then previous one login user logout auto.
any suggestion how to implement concurrent login
same user account cannot access from multiple browser. if user login from two browser then previous one login user logout auto.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sardar Mudassar Ali KhanPosted Mar 1, 2023, 12:24 PM
Follow given below artcile for help
https://www.c-sharpcorner.com/forums/how-to-prevent-concurrent-login-of-user-from-multiple-browser
Naimish MakwanaPosted Mar 1, 2023, 8:06 AM
Hello Tahir,
To implement concurrent login in .NET, you can follow these steps:
Keep track of active user sessions on the server: Whenever a user logs in, you can create a new session object on the server and store it in a dictionary or some other data structure or database. The session object should contain information about the user, such as their user ID and the time when the session was created.
Check for existing sessions when a user logs in: Whenever a user tries to log in, you should check if they already have an active session on the server. If they do, it means that they are already logged in from another browser or device, so you can log them out of that session automatically.
Invalidate old sessions: Once you have identified the old session to log out, you can invalidate the session by removing it from the dictionary or updating its state to indicate that it is no longer active. You can also send a message to the user's other device or browser indicating that they have been logged out.
Redirect the user: Once you have logged out the old session, you can redirect the user to their account page or some other appropriate page.
Thanks
Naimish Makwana
Rajeev KumarPosted Mar 1, 2023, 7:48 AM
According to your description, I recommend that you try to use cache. When the user login successfully, create a cache entry for the user and save the unique sessionID.
Something like:
And at the end of the session, delete the cached information. For example, Session_End event in global.asax:
The Cache is better managed and can be made to be synced across web farms or multiple threads with functions such as load balancing. Others (static or application) are only in the process, in this case there will be no guarantee for a single object. But if this is not the case, you could also use the static dictionary mentioned by other members.