【发布时间】:2020-11-09 09:17:20
【问题描述】:
所以我希望我的应用程序在身份验证超时后自动重定向到登录页面。 我正在使用 mvc 核心,当用户登录时,我正在设置身份验证 cookie
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
//options.SlidingExpiration = true;
options.LoginPath = "/Authentication";
options.LogoutPath = "/Authentication";
options.AccessDeniedPath = "/Authentication/Denied";
options.ExpireTimeSpan = new TimeSpan(0, 1, 0);
options.SlidingExpiration = false;
});
加上 Authorize 属性,当超时时我被重定向到登录页面如果我点击一个具有该属性的元素。
我也希望自动重定向,例如,如果我在表单上并且空闲时间过长然后被重定向,而不是等待用户点击正确的位置。
我读过一些关于会话超时的帖子,但我没有找到任何解释会话 cookie 和身份验证 cookie 之间区别的内容。
【问题讨论】:
标签: c# asp.net-core authentication model-view-controller