authentication - asp.net core cookie 身份验证滑动过期不起作用
问题描述
我在asp.net core 2应用中配置了cookie认证,这里是startup,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 分钟内注销,无论您是否在网站上进行工作。
解决方案
推荐阅读
- c# - 将 IConfiguration 绑定到 C# 记录类型
- firebase - Nuxt 中间件:如何访问 vuex 商店?
- phpstorm - PHP 语言级别缺少最新(版本 7.3 是最高的)
- c - 如何在 C 中创建模块
- java - fusedLocationProvider 在主线程上运行,即使方法是从不同的可运行线程调用的
- reactjs - Code not working after redux function in axios call
- ios - 如何在不打开父应用程序的情况下使用 SwiftUI for Widget 添加点击事件和更新视图?
- python - 如何使用 Pyspark 根据条件从另一个表更新表的 Spark DataFrame 列值
- android - 谷歌应用操作审核流程的时间长度是多少?
- http - 上传视频的大小在服务器上为 0,即使视频有大小