title: ASP.NET Core not redirecting to logIn page after session times out
body: <p>I've following configuration I've <code>LockOut.DefaultLockoutTimeSpan</code> set to <code>2 hours</code> and <code>ApplicationCookie.ExpireTimeSpan</code> set to <code>one day</code>. But if the app is idle for 2 hours it does not redirect the user to <code>login page</code>. In the <code>View</code> below, I'm using <code>Ajax</code> where a click event of a tab in a tabstrip gets an id of the tab and passes it to a calling action method. But I noticed that if I leave the app idle for 2 hours and click on the tab it passes the id value as null and hence, as expected, the action method fails and the alert message in the error block of Ajax method is displayed. <strong>Question</strong>: How can I make the app to redirect to login page when login session expires? Obviously, I'm missing something in the code below. I'm using ASP.NET Identity-3 for authentication.</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>What is happening is that I've three important session variables that are storing some values that are used across the pages. And those values are getting lost after every 15-20 minutes or so. And hence application is throwing error message in the alert(...) dialog of error blocks of Ajax code. So I thought it has something to do with authentication cookie expiring earlier. But it seems the issue is more related to session expiring earlier than I need it to.</p>
  
  <p><strong>StartUp.cs</strong></p>
  
  <pre><code>...
  public void ConfigureServices(IServiceCollection services)
  {
     ...
  
      // Add framework services.
      services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
      services.AddIdentity&lt;ApplicationUser, ApplicationRole&gt;()
          .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
          .AddDefaultTokenProviders();
  
      services.AddMvc();
      services.AddDistributedMemoryCache();
      services.AddSession();
  
      services.Configure&lt;IdentityOptions&gt;(options =&gt; {
          // Lockout settings
          options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(120); //The amount of time in minutes a user is locked out when a lockout occurs
  
          // Cookie settings
          options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(1); //Controls how much time the authentication ticket stored in the cookie will remain valid from the point it is created. Defaults to 14 days.
          options.Cookies.ApplicationCookie.LoginPath = "/Account/LogIn"; //When a user is unauthorized, they will be redirected to this path to login. Defaults to /Account/Login.
          options.Cookies.ApplicationCookie.LogoutPath = "/Account/LogOut";
      });
  
      // Add application services.
      services.AddTransient&lt;IEmailSender, AuthMessageSender&gt;();
      services.AddTransient&lt;ISmsSender, AuthMessageSender&gt;();
  }
  ...
  </code></pre>
  
  <p><strong>MyView</strong>:</p>
  
  <pre><code>&lt;html&gt;
  ...
  &lt;div&gt;Tabstrib here with tab1, tab2&lt;/div&gt;
  ...
  @section scripts
  {
      @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
      &lt;script&gt;
          $(document).ready(function () {
              ...
  
          $('#myTabstripID li').click(function () {
              var li_id = $(this).attr("id");
              $.ajax({
                  url: '@Url.Action("ActionName", "ContrlName")',
                  data: { calledFrom: li_id },
                  contentType: 'application/json',
                  dataType: 'html',
                  type: 'GET',
                  cache: false,
                  success: function (data) {
                      if (li_id == 'Tab1')
                          $('#menuAP').html(data);
                      else if (li_id == 'Tab2')
                          $('#menuUP').html(data);
                  },
                  error: function (jqXHR, textStatus) {
                      alert('Error occurred');
                  }
              });
          });
      ...
  }
  </code></pre>