title: Shared session state access between Controllers invoked via AJAX
body: <p>I am trying to provide a progress monitoring mechanism for a longish-running request implemented by an AsyncController. A web page invokes (via JQuery <code>$.post</code>) the asynchronous StartTask action on the following controller...</p>
  
  <pre><code>[NoAsyncTimeout]
  public class TaskController: AsyncController
  {
     [HttpPost]
     public void StartTaskAsync()
     {
        AsyncManager.OutstandingOperations.Increment();
        Session["progress"] = "in progress";
        Task.Factory.StartNew(DoIt);
     }
  
     public ActionResult StartTaskCompleted()
     {
        return Json(new {redirectUrl = Url.Action("TaskComplete", "First")});
     }
  
     private void DoIt()
     {
        try
        {
           // Long-running stuff takes place here, including updating 
           // Session["progress"].
        }
        finally
        {
           AsyncManager.OutstandingOperations.Decrement();
        }
     }
  }
  </code></pre>
  
  <p>The same web page sets up a 2-second timer (via window.setInterval) to call the following controller (via JQuery <code>$.getJSON</code>) that has read-only access to the session...</p>
  
  <pre><code>[SessionState(SessionStateBehavior.ReadOnly)]
  public class ProgressController: Controller
  {
      [HttpGet]
      public ActionResult Current()
      {
         var data = Session["progress"];
         return Json(data, JsonRequestBehavior.AllowGet);
      }
  }
  </code></pre>
  
  <p>The function invoked after getJSON returns updates a DIV to show the current progress. Ultimately the progress will be updated in the session by the 'long-running stuff takes place here' code, but as it is the call to ProgressController.Current() does not find any data in the session and always returns null.</p>
  
  <p>I had assumed that JQuery AJAX requests sent from the same browser to the same IIS server would end up with the same session, but it seems not. Do I need to explicitly set the ASP.NET session key on these $.post and $.getJSON calls? Or is it just not possible to share session state between Controllers (even if one has R/O access) in this way (I can fall back to a slightly hacky solution with Application state and GUIDs).</p>