title: How to make entire page redirect to login after session expires in mvc?
body: <p>I have this attribute overridden and decorated it on each controller which does its job perfectly on all normal views: </p>
  
  <pre><code>public class MyAuthorize : AuthorizeAttribute
  {
      protected override bool AuthorizeCore(HttpContextBase httpContext)
      {
          var authroized = base.AuthorizeCore(httpContext);
          if (!authroized)
          {
              // the user is not authenticated or the forms authentication
              // cookie has expired
              return false;
          }
  
          // Now check the session:
          var checkUser = httpContext.Session["LoggedUserID"];
  
          if (checkUser == null)
          {
              // the session has expired
              return false;
          }
  
          return true;
      }
  }
  </code></pre>
  
  <p>And I have this one of many cases where I need to update a certain partial view within a parent view:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(function () {
      $(".sensor-delete-table").on("click", function () {
          var divSensorNames = $("#sensorNames");
          var tr = $(this).parents('tr:first');
          var PredefineViewsItemID = tr.find("#PredefineViewsItemID").html();
          var PredefineViewID = tr.find("#PredefineViewID").html();
          var amount = parseInt($("[data-id='" + PredefineViewID + "']").text());
          var flag = confirm('@Html.Localize("deleteCheck")');
          var urlShowNewSensors = "@Url.Action("ShowSensorNames", "PredefinedViews", new { predefinedViewID = "PredefineViewID" })";
          urlShowNewSensors = urlShowNewSensors.replace("PredefineViewID", PredefineViewID);
          if (PredefineViewID != "" &amp;&amp; flag) {
              $.ajax({
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  url: '@Url.Action("DeleteSensor", "PredefinedViews")',
                  data: JSON.stringify({ pviID: PredefineViewsItemID, pID: PredefineViewID }),
                  dataType: "json",
                  complete: function () {
  
                      var urlShowSensors = "@Url.Action("ShowSensorNames", "PredefinedViews", new { predefinedViewID = "PredefID" })";
                      urlShowSensors = urlShowSensors.replace("PredefID", PredefineViewID);
                      $(divSensorNames).load(urlShowSensors); //this is the partial view inside the parrent view that I'm updating
                  },
  
              });
          }
      });
  });
  </code></pre>
  
  <p></p>
  
  <p>What happens here is that if the session "LoggedUserID" is expired, what it will do is it will only redirect that div container divSensorNames (where the partial view is) to the login page but leave the entire parrent page stuck where it was. So I end up with a stupid looking site. <strong>What I want here of course is for the entire page to redirect to the login</strong> Any suggestions or modifications I should make to have my cite function normally? Basically I have all the functionality working without a hitch, except this "small cosmetics problem".</p>
  
  <p>I also have this in my web.config:</p>
  
  <pre><code>&lt;system.web&gt;
  &lt;sessionState mode="InProc" timeout="30" /&gt;
  &lt;compilation debug="true" targetFramework="4.5.1" /&gt;
  &lt;httpRuntime targetFramework="4.5.1" /&gt;
  &lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="~/Welcome/Login"&gt;&lt;/forms&gt;
  &lt;/authentication&gt;
  </code></pre>
  
  <p></p>
  
  <p>My logout method:</p>
  
  <pre><code>public ActionResult Logout()
      {
          Session.RemoveAll();
          FormsAuthentication.SignOut();
          return RedirectToAction("Login", "Login");
      }
  </code></pre>