'.NET Core Razor pages Automatic Logout and Redirect

I have .NET Core Razor pages application. I would like to automatically logout the application when idle for 30 minutes. Any ideas on how to achieve?

Currently, it logs out after 30 mins but doesn't automatically redirect to login page.

Below is the code in Startup.cs

   services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath = $"/Account/Login";
                options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
                options.LogoutPath = $"/Account/Logout";
                options.AccessDeniedPath = $"/NotAuthorized";
                options.SlidingExpiration = true;
            });

            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(30);
                options.Cookie.HttpOnly = true;
            });

I need immediate help on this one.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source