Click here to Skip to main content
15,902,817 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Session Pin
m-khansari16-Dec-09 1:25
m-khansari16-Dec-09 1:25 
GeneralRe: Session Pin
Rock Star.16-Dec-09 1:34
Rock Star.16-Dec-09 1:34 
GeneralRe: Session Pin
m-khansari16-Dec-09 2:30
m-khansari16-Dec-09 2:30 
AnswerRe: Session Pin
Abhishek Sur16-Dec-09 1:35
professionalAbhishek Sur16-Dec-09 1:35 
GeneralRe: Session Pin
Rock Star.16-Dec-09 2:12
Rock Star.16-Dec-09 2:12 
GeneralRe: Session Pin
Abhishek Sur16-Dec-09 6:03
professionalAbhishek Sur16-Dec-09 6:03 
AnswerRe: Session Pin
DJ Matthews16-Dec-09 2:30
DJ Matthews16-Dec-09 2:30 
GeneralRe: Session Pin
Paulo Zemek16-Dec-09 9:29
Paulo Zemek16-Dec-09 9:29 
The solution I will give you will only work if you are NOT in a web-farm and if you have a Session manager that supports informing you when a session dies.

Create a dictionary, like:
C#
private static Dictionary<string, string> _someDictionaty = new Dictionary<string, string>();


Each time a user log-ins (after you validated the password) will do:
C#
lock(_someDictionary)
  _someDictionary[...loginHere...] = HttpContext.Current.Session.SessionID;


Except from the login page, you must check if the "actual" session is the active session for logged user. So:

C#
string activeSessionId;
lock(_someDictionary)
{
if (_someDictionary.TryGetValue(...loginHere..., out activeSessionId)
{
    // Some old session was found for this ID, so check if it is the same or not.
    if (activeSessionId != HttpContext.Current.Session.SessionID)
       // the activeSession is not this... so, show an error? Redirect to login?
  }
  else
  {
    // There is no session registered for this login. Is this an error?
  }
}



And finally, in Global.asax, in the Session_End method, you must remove the session for that user, so:
C#
var pair = new KeyValuePair<string, string>(...loginHere..., HttpContext.Current.Session.SessionID);
IDictionary<string, string> dictionary = _someDictionary;

lock(_someDictionary)
  dictionary.Remove(pair);


I used the Remove that accepts a key/value pair because if a session ends that is not the valid one we must simple ignore it.
GeneralRe: Session Pin
Rock Star.17-Dec-09 3:35
Rock Star.17-Dec-09 3:35 
GeneralRe: Session Pin
Rock Star.18-Dec-09 4:47
Rock Star.18-Dec-09 4:47 
GeneralRe: Session Pin
Paulo Zemek18-Dec-09 10:11
Paulo Zemek18-Dec-09 10:11 
GeneralRe: Session Pin
Rock Star.20-Dec-09 20:41
Rock Star.20-Dec-09 20:41 
Questionsuggest word when typed on Textbox Pin
Any_India16-Dec-09 0:55
Any_India16-Dec-09 0:55 
AnswerRe: suggest word when typed on Textbox Pin
Abhijit Jana16-Dec-09 2:09
professionalAbhijit Jana16-Dec-09 2:09 
QuestionIssue with Cached user control Pin
kingshez16-Dec-09 0:54
kingshez16-Dec-09 0:54 
AnswerRe: Issue with Cached user control Pin
Abhishek Sur16-Dec-09 6:53
professionalAbhishek Sur16-Dec-09 6:53 
GeneralRe: Issue with Cached user control Pin
kingshez16-Dec-09 19:17
kingshez16-Dec-09 19:17 
QuestionASP.NET With C# Pin
sanforjackass16-Dec-09 0:02
sanforjackass16-Dec-09 0:02 
AnswerRe: ASP.NET With C# Pin
Abhijit Jana16-Dec-09 0:23
professionalAbhijit Jana16-Dec-09 0:23 
QuestionRe: ASP.NET With C# Pin
sanforjackass16-Dec-09 0:40
sanforjackass16-Dec-09 0:40 
AnswerRe: ASP.NET With C# Pin
Abhishek Sur16-Dec-09 1:31
professionalAbhishek Sur16-Dec-09 1:31 
AnswerRe: ASP.NET With C# Pin
#realJSOP16-Dec-09 3:34
professional#realJSOP16-Dec-09 3:34 
QuestionEmails are going to spam folder Pin
jinovv15-Dec-09 23:52
jinovv15-Dec-09 23:52 
AnswerRe: Emails are going to spam folder Pin
sashidhar15-Dec-09 23:56
sashidhar15-Dec-09 23:56 
AnswerRe: Emails are going to spam folder Pin
tonymathewt16-Dec-09 0:08
professionaltonymathewt16-Dec-09 0:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.