I am working on .net core 6 MVC project, in which i want to logout the user automatically and redirect to login page, after session idle timeout.
please see the below code i have written in program.cs file:
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(Convert.ToInt32(builder.Configuration.GetValue<string>("SessionTime")));
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
Controller code while login in system:
await _signInManager.SignInAsync(
user,
new AuthenticationProperties
{
IsPersistent = true,
RedirectUri = "/Account/Login",
ExpiresUtc = DateTime.UtcNow.AddSeconds(Convert.ToInt32(_configuration.GetValue<string>("SessionTime"))),
AllowRefresh = true
});
please help, thanks in advance.
What I have tried:
please see the below code i have written in program.cs file:
<pre>builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(Convert.ToInt32(builder.Configuration.GetValue<string>("SessionTime")));
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
Controller code while login in system:
await _signInManager.SignInAsync(
user,
new AuthenticationProperties
{
IsPersistent = true,
RedirectUri = "/Account/Login",
ExpiresUtc = DateTime.UtcNow.AddSeconds(Convert.ToInt32(_configuration.GetValue<string>("SessionTime"))),
AllowRefresh = true
});