Я настроил cookie-аутентификацию в приложении asp.net core 2, здесь конфигурация при запуске, файл cs
//1:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme,
options =>
{
//REF:https://tahirnaushad.com/2017/09/08/asp-net-core-2-0-cookie-authentication/
//Cookie Authentication Options
//Login View
options.LoginPath = "/Account/Login";
//Logout Action
options.LogoutPath = "/Account/Logout";
//Controls how much time the cookie will remain valid from the point it is created.
options.SlidingExpiration = true;
//Ticket Expiration :represents the expiration of the ticket NOT the cookie that contains the ticket.
//an expired cookie will be ignored even if it is passed to the server after the browser should have purged it.
options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
//Cookie Expiration
options.Cookie.Expiration = TimeSpan.FromMinutes(10);
//override default name of cookie, which is .AspNetCore.Cookies
options.Cookie.Name = "HDAPP1.0";
//cookie can be accessed from client side scripts
options.Cookie.HttpOnly = false;
//ReturnUrlParameter = "returnUrl"
});
//2:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
});
//3:add app.UseAuthentication(); in Configure Method
Проблема в том, что скользящий срок действия не работает, и приложение всегда выходит из системы10 минут, либо вы работаете на веб-сайте, либо нет.