Click here to Skip to main content
15,905,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
});
Posted

1 solution

I popped your question into Google Search and found many solutions. Here is the first one returned: Redirect back to login page after session timeout ASP.NET 5 MVC 6[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900