title: How do you cancel an AJAX long running MVC action client side (in javascript)?
body: <p>I have a long running (4-10 second) MVC action that runs a report from an AJAX call. While it's running users can change the parameters and run something else, so I cancel the AJAX request before making another one.</p>
  
  <p>So, for instance (example in jQuery but the problem happens regardless):</p>
  
  <pre><code>// If we have an active request and it's not complete
  if(dataRequest &amp;&amp; dataRequest.readyState != 'complete') 
  {
      dataRequest.abort();
  }
  
  dataRequest = $.ajax(...);
  </code></pre>
  
  <p>Client side this appears to work fine, but the cancelled request is still running on the server. For instance if the report takes 10 seconds, and I cancel one and start the other then the second request takes 20 seconds.</p>
  
  <p>I think this is due to the <a href="http://msdn.microsoft.com/en-us/library/ms178581.aspx" rel="noreferrer">session level locking</a>:</p>
  
  <blockquote>
    <p>[If] two concurrent requests are made for the same session (by using
    the same SessionID value), the first request gets exclusive access to
    the session information. The second request executes only after the
    first request is finished.</p>
  </blockquote>
  
  <p>So the second request can't access the session until the first one finishes. Using asynchronous MVC actions doesn't seem to get around this as the action still needs to be able to make changes to the session.</p>
  
  <p>Is it possible to stop one action and start the next without using <code>AsyncController</code> or <code>[SessionState(SessionStateBehavior.ReadOnly)]</code>?</p>
  
  <p>If it isn't are both required?</p>