title: Ajax request after MVC authentication timeout/session cookie deleted
body: <p>Using MVC 5 authentication when a user times out, or the session cookie cookie is deleted, the user gets redirected to the login page.</p>
  
  <p>This works fine on full page loads, however for my Ajax calls this breaks client side. The redirect works as the authentication page shows up, but is unresponsive (behind the standard loading wheel).</p>
  
  <p>I'm pretty sure this is some sort of JS issue.</p>
  
  <p>JS:</p>
  
  <pre><code>$(function () {
      $('#dealSearchForm').on("submit", function (e) {
          e.preventDefault();
          $.ajax({
              url: this.action,
              type: this.method,
              data: $(this).serialize(),
              success: function (data) {
                  $('#dealSearchForm').html(data);
              },
              complete: function (data) {
                  $('#searchResults').show();
              }
          });
      });
  });
  </code></pre>
  
  <p>Main View:</p>
  
  <pre><code>@{Html.RenderPartial("_DealSearch");}
  
  &lt;script src="@Url.Content("~/Scripts/DealSearch.js")"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
      $(document).ready(function () {
          @if (Model.Deals.Count &gt; 0) {
              @Html.Raw("$('#searchResults').show();");
          }
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Partial View:</p>
  
  <pre><code>@using (Html.BeginForm("DealSearch", DealManagement, FormMethod.Post, new { @id = "dealSearchForm" }))
  {
  /* Search filters etc */
  
  &lt;div class="col-xs-7"&gt;
      &lt;button id="button-search" class="btn btn-primary pull-right" type="submit" data-loading-text="Please wait..."&gt;Search&lt;/button&gt;
  &lt;/div&gt;
  
  &lt;div id="searchResults"&gt;
      /* Grid with results */
  &lt;/div&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public virtual ActionResult Index()
          {
              var model = new DealSearchModel();
  
              return this.View(model);
          }
  
  public virtual ActionResult DealSearch(DealSearchModel model)
          {
              // Get deals from service, uses search criteria
              model.Deals = GetDeals(model);
  
              // Return the view
              return PartialView(MVC.DealManagement.Views._DealSearch, model);
          }
  </code></pre>
  
  <p>I get errors client side:</p>
  
  <p><a href="https://i.stack.imgur.com/B0WeM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B0WeM.png" alt="Error client side"></a></p>
  
  <p>If anyone has any ideas they'd be very much appreciated!</p>