0

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

Matheus Dasuke
  • 261
  • 3
  • 9

1 Answers1

0

Try this:

services.AddAuthentication().AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => { options.ExpireTimeSpan = System.TimeSpan.FromMinutes(authenticationTimeOut); })
S.A.Parkhid
  • 2,772
  • 6
  • 28
  • 58