Click here to Skip to main content
15,900,616 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
In my asp.net website, I want to prevent same user login into website simultaneously from two different browsers. In order to do so, I had created table (say userloggedin)  that will store user id and time once user login. when user attempts to login from different browser, user will not be redirected into website from that new browser he is attempting to login (if user's record is in userloggedin table). 

User's record will be deleted when user logout, thus clearing log for allowing next time login.

The problem i am facing using this approach is when user clicks on close button from title bar, browser closes. Here, record will not be deleted from userloggedin table.( i need to delete from this table to allow future login). I had used window.onbeforeunload and kept a code to delete from userloggedin in here. But this function gets fired on every postback. 

How can i delete record from userloggedin table on click of close button? Any alternative approach is welcome..


What I have tried:

I had created a table userloggedin to store record of user logged in. Then, when user login from another browser, this table is checked. If there is his data in this table, he is not allowed to login.
Posted

 
Share this answer
 
Normally a user will be automatically signed out after some time beeing inactive. Logout users using events or anything because there could also be a loss of the internet connection or a complete crash of the user's computer. So you can never be sure.
When a user does a succesful login from another browser you simply clear the old record first before writing a new one or overwrite the existing. This will effectively logout the user in the other browser.

This is all default implementation by the way that can be simply created by starting a new web project with the right template providing login functionality. It is normally much harder to allow a user to be logged in multiple times because the default implementation clears the other session and with it logs out the same user in another browser.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900