I have the following code:
Startup.cs in .NET 5 MVC project.
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/Auth/Login";
options.Cookie.Name = "MyWebsite";
options.ExpireTimeSpan = TimeSpan.FromHours(8);
options.SlidingExpiration = true;
options.LogoutPath = "/Auth/Logout";
options.AccessDeniedPath = "/Error/AccessDenied";
});
Login Controller - I also tried setting IsPersistent = true
ClaimsIdentity claimsIdentity = new ClaimsIdentity(Claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{
IsPersistent = true
};
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);
But after 30 minutes my website goes to the login page ("auto logout"). What am I doing wrong?
By the way, I also checked out the same question: similar question