title: Redirect to Login page after session expire or idle time in MVC application using ASP.net core C#
body: <p>I am using ASP.NET Core. I want to redirect to login page when session expires or user is idle for 10 min. How can I achieve this? Currently, logout is happening (as when user clicks on any link or submits button, application gets redirect to login page. This happens when user clicks on button or link.) I want to redirect to happen to login page without user clicking on button or link.</p>
  <p>Currently I have written this code in Startup.cs</p>
  <ol>
  <li><p>Inside ConfigureServices</p>
  <pre><code>     services.AddSession(options =&gt; {
           options.IdleTimeout = TimeSpan.FromMinutes(10);
  
       });
       services.AddMvc(options =&gt; options.EnableEndpointRouting = false);
  
       services.ConfigureApplicationCookie(options =&gt;
       {
           options.ExpireTimeSpan = System.TimeSpan.FromMinutes(10);
           options.SlidingExpiration = true;
           options.LoginPath = &quot;/MVCApp/Login&quot;;
       });
  </code></pre>
  </li>
  <li><p>In Configure</p>
  <pre><code>     app.UseSession();
       app.UseEndpoints(endpoints =&gt;
       {
           endpoints.MapControllerRoute(
               name: &quot;default&quot;,
               pattern: &quot;{controller=Home}/{action=Index}/{id?}&quot;);
  
           endpoints.MapRazorPages(); 
       });
       app.UseMvc(routes =&gt;
       {
           routes.MapRoute(
               name: &quot;default&quot;,
               template: &quot;{controller=Home}/{action=Index}/{id?}&quot;);
       });
  </code></pre>
  </li>
  </ol>
  <p>any suggestion on this.</p>