Click here to Skip to main content
15,610,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on Asp. net application. My reuqiremnt is i want to maintain unique session for each userid after login.
For example, if userid "ABC" is already logged in then next if same user tries to login from any browser then it should not allowed to access.

You can do that quite easily, but you have to add some caveats.
It's pretty simple - all you do is add a "logged in" field to your login database and check it when they try to log in. If it is set, then refuse the login. If it isn't, log them in and set it.

The problem comes when they don't log out. If their browser or the page closes for any reason without actually logging them out first (which is pretty damn easy to do) then they will never be able to log in again, unless you reset them.

So it would make the "logged in" field a date/time field and check it - when they interact with your app, update the datetime to a "termination time" and check if that has expired when they attempt a log in. If they do log out set the expiry time to 1/1/2001 and you are all set.

If you set the termination period to your standard session length then it all works together without problems - if they don't log out, they have to wait 10 or 20 minutes, but then they can log in again.
Share this answer
Abhijit Parab 29-Jan-13 5:34am    
Thank you sir for suggestion but when application is getting close directly without logout then how can i track and update "logged in" field?
OriginalGriff 29-Jan-13 5:39am    
That's the whole idea - you don't. Because when the user interacts with your site you update the "logged in" field to (say) twenty minutes in the future, if the user doesn't log out, then in twenty minutes he can because the timeout has expired. If he doeslog out, then he can log in again immediately.
Share this answer
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