title: Can ASP.NET Session ID be the same on two machines at the same time?
body: <p>I have an ASP.NET application that uses Session.SessionID to prevent multiple users viewing the same data at the same time.</p>
  
  <p>I have a table that contains a set of images (stored in BLOB) that require processing.  Only one user is supposed to be able to view the same image at the same time.  To achieve this, as each record is retrieved by a user the record is updated with the Session.SessionID.  This update occurs inside a ReaderWriterLock.</p>
  
  <p>I have done a test to ensure the ReaderWriterLock is working correctly and can confirm that only one session can execute the code inside that block at once.</p>
  
  <p>My current theory is that two different users are getting the same SessionID at the same time.  A user of this application is allowed to view records they have locked or any unlocked images.</p>
  
  <p>I have modified the application to display the SessionID in the footer of every page so that if the problem happens again I can check the SessionID value.</p>
  
  <p>I've seen some articles online suggesting that SessionID is not unique and some saying that the SessionID is unique.  I understand that SessionID is not unique forever but can the SessionID value be considered unique for active sessions?</p>
  
  <p><a href="http://forums.asp.net/p/413704/416543.aspx" rel="nofollow noreferrer">This forum describes a similar problem</a></p>
  
  <p>I have also read some suggestions that a Guid should be stored in the Session object and used as a unique ID instead of the Session ID.</p>
  
  <p>Thanks for the responses so far.  Here is a clarification based on the answers so far:</p>
  
  <p>"Locked forever" - we prevent this by a lock timeout of 5 minutes.  Before a user locks an image, while inside the ReaderWriterLock, we do a "cleanup" of old locks (which unlocks images locked for more than 5 minutes), a query to get the oldest unlocked image and an update statement to "lock" that image to the current session.</p>
  
  <p>A possible cause of the problem would be if one user "locks" an image but then leaves the PC for a short break.  If they did nothing for 5 minutes, that image on there screen would be unlocked and potentially opened by another user.  I mentioned this scenario when the problem was reported and I was assured that the users had been working continuously.</p>
  
  <p>"Different Window/Tab" - I haven't actually seen the error with my own eyes but the person who reported the problem has told me that it is two different PC's and two different usernames of the logged in user.</p>
  
  <p>Hopefully now that I am displaying the Session ID on the page, next time it happens I will be able to say with certainty whether it is the same Session ID on two machines or if it is some other problem.  This issue has never occurred during the testing phase so it appears to be a symptom of a larger number of concurrent users.</p>
  
  <p>Thanks for the responses so far and I will update this question as more information comes to hand.</p>
  
  <p>It seems that the user didn't give me the full story.  Session ID is unique in our case as per the accepted answer.  Two users were able to see the same image at the same time because user 1 was idle for the 5 minute "abandoned image" unlock process.  The "abandoned image" timeout has been raised to match the session timeout to avoid this problem.</p>