Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET session
Hi,
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.
Posted 28-Jan-13 23:17pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Abhijit Parab at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 BillWoodruff 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100