My website sessions timeout every ten seconds in the hosting environment, but works fine in my local development environment. I have been unable to change the timeout.
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(600);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
I have even tried the above configuration, but it's not working; it still times out after ten seconds, even the operations are done.
It is up to you to write middleware logic that checks if the Session exists and redirect when Session does not exist.
A much better approach is using the standard Cookie Authentication that comes with ASP.NET Core. It has the redirect feature built-in.
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-3.0