title: User.Identity.IsAuthenticated true after logout asp.net mvc
body: <p>i have a function having a loop which sleeps for 6 second at the end of each loop </p>
  
  <p><code>Thread.Sleep(TimeSpan.FromSeconds(6));</code> 
  this loops 10 times ie the function runs for 60 seconds, each time takin a pause for 6 seconds. </p>
  
  <p>i have authentication test at starting of loop</p>
  
  <pre><code> if (!HttpContext.Current.User.Identity.IsAuthenticated)
                  {
                      return null;
                  }
  </code></pre>
  
  <p>so each time it firsts authenticate then run and wait for 6 seconds.</p>
  
  <p>This is my function:</p>
  
  <pre><code>while (counter &lt; 10)
  
              {
                  if (!HttpContext.Current.User.Identity.IsAuthenticated)
                  {
                      return null;
                  }
  
                  // doing stuff
  
                  Thread.Sleep(TimeSpan.FromSeconds(6));
                  counter++;
              }
  </code></pre>
  
  <p>now the user logs out in meantime (say in 15th second) .  i use ajax to logout and hence dont want to redirect my page. even after logout IsAuthenticated is always true for all 10 loops and is false only when this function is re-executed</p>
  
  <p>for logout i use:</p>
  
  <pre><code>FormsAuthentication.SignOut();
  Session.Abandon();
  Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
  Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
  HttpCookie cookie = HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName];
                  if (cookie != null)
                  {
                      cookie.Expires = DateTime.Now.AddDays(-1);
                      Response.Cookies.Add(cookie);
                  }
  </code></pre>
  
  <p>but still its true..
  <strong>i want to stop execution of my thread as soon as user logs out</strong></p>