title: ASP.NET Session identifier
body: <p>I'm trying to make a session code for each client on my site. In the Session_Start of the global asax I have this code:</p>
  
  <pre><code>private static long codSesion = 0;
  private static object codSesionLocker = new object();
  protected void Session_Start(object sender, EventArgs e)
  {
      if (Session["CodSesion"] == null)
      {
          lock (codSesionLocker)
          {
              if (Session["CodSesion"] == null)
              {
                  if (codSesion == 9999)
                      codSesion = 0;
                  codSesion++;
                  Session["CodSesion"] = codSesion;
              }
          }
  
      }
  }
  </code></pre>
  
  <p>When I monitor this it seems to be perfect. After some time of inactivity starts the problems. One of the thing that happens is that too many times starts over from 1 (without reaching 9999 and without IIS rebouting). And recently, even worst than taht: I'd used the codes 1 and 2. I stop using the server (leting the IIS without activity). After almost 1 hour (50 minutes) I tried again. The code the IIS gave me was 2 (in a different PC than the last code 2).</p>
  
  <p>Please I'd realy apreciate any help with this.</p>