title: ASP.net MVC - AsyncController and Session
body: <p>I was playing around with asynchronous controllers in ASP.net MVC just to see how they work. In one of my asynchronous action methods I wanted to simulate a long running method by looping a few times and doing a Thread.Sleep:</p>
  
  <pre><code>for(int x = 1; x &lt;= 10; x++) {
      Thread.Sleep(1000);
  
      Session["progress"] = x * 10;
  }
  </code></pre>
  
  <p>I wanted a quick and dirty way of reporting the progress of the long running operation so I just used session state. I wouldn't use it in a normal application but I noticed that in another non-asynchronous action method this session state was not being persisted:</p>
  
  <pre><code>public ActionResult ReportProgress() {
      int progress = 0;
  
      if( Session["progress"] != null ) {
          progress = (int)Session["progress"];
      }
  
      return Json(progress);
  }
  </code></pre>
  
  <p>In the ReportProgress method, this session variable is always null. When I debug the other async method, Session is being persisted.</p>
  
  <p>Does anyone have any insight into why the asynchronous method and the synchronous method don't appear to have the same session?</p>