title: ASP.NET Different Session Variable Value on the Web Service
body: <p>I have been trying to solve this problem for 2 days now and I haven't been able to find anything useful on the net yet. Strange thing is, this used to work..! After changing some settings on the web server (unfortunately I don't recall exact changes) It ceased to work :(</p>
  
  <p>Here is what happens;</p>
  
  <p>I have a hidden field on an aspx page whose value gets set to the current datetime string(long datetime sting, seconds included) on page_load (aspx.cs, codebehind). At the same time, this random value is recorded in a session variable right on the next line in the same method.</p>
  
  <p>Than (to explain briefly) I send this value to a web service where I check this value against the value stored in the session variable. Guess what..there are not the same! This used to work but not anymore and I don't know what changed or went wrong. Since the value of this string is datetime value (with seconds), I can see that this value is changing by 2 seconds "Most of The Time". When I debug the code on the IIS (by attaching the worker process) I can see that the value recovered from the session is 2 seconds later from the value recovered from the hidden field.</p>
  
  <p>This is working on my development machine, problem is, it is not working on the web server (Windows server 2008 r2)</p>
  
  <p>I know there are alternatives you can propose, I myself can think of alternatives to this approach too, but I am really very much interested in solving the puzzle here...</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Thanks.</p>
  
  <p>edit: simple approach</p>
  
  <p><strong>method call on the page_load</strong></p>
  
  <pre><code>addSecureString(System.DateTime.Now.Second.ToString());
  </code></pre>
  
  <p><strong>method that records the vaiables</strong></p>
  
  <pre><code>protected void addSecureString(string s) {
  
          string secureS = "111" + s;
          Session.Add("securestring", secureS);
          hdnss.Value = Session["securestring"].ToString();
  
  }
  </code></pre>
  
  <p><strong>on the web service</strong></p>
  
  <pre><code>string tocheck = Session["securestring"];
  </code></pre>
  
  <p>hdnss -> id of the hidden field on the page
  Note: I am taking the Seconds value of the datetime since that is the part that matters and changing..</p>