I use owin and although I have set the expired time defined in Startup.cs as 1 day, it exits itself after 15 minutes when the site is open in browser.Besides, when I run it on my localhost, I do not encounter such a problem.When I right click and look at the cookies in the applications, the expires actually looks correct.application />cookies
- app.UseCookieAuthentication(new CookieAuthenticationOptions
- {
- ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter,
- ExpireTimeSpan = TimeSpan.FromDays(1),
- SlidingExpiration = true,
- CookieHttpOnly = true,
- AuthenticationType = "Cookie",
- LoginPath = new PathString("/Admin/Login"),
- Provider = new CookieAuthenticationProvider
- {
- OnResponseSignIn = context =>
- {
- context.Properties.AllowRefresh = true;
- context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddDays(1);
- }
- }
- });
- app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
My sign in function is as follows,
- var claims = new Claim[]
- {
- new Claim(ClaimTypes.NameIdentifier,model.id),
- new Claim(ClaimTypes.Name,model.username),
- new Claim(ClaimTypes.Role,"Admin")
- };
- var identity = new ClaimsIdentity(claims, "Cookie");
- Authentication.SignIn(new AuthenticationProperties() { ExpiresUtc = DateTime.UtcNow.AddDays(1), IsPersistent = true }, identity);