我正在构建 C# (.net core 2.1) Razor Page 站点。登录机制将基于此处的文档工作 - 所以 cookie 中的令牌(如果我理解正确的话):https : //docs.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore- 2.1
假设我将会话设置为 3 分钟,如果用户正在积极使用站点,我将重置此值。如果他不是,在令牌到期前 30 秒,我想向他展示诸如“做点什么,否则您将被注销”之类的消息。
我的问题 - 我找不到获得这个“过期”时间的方法。
这就是我验证和存储数据的方式:
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
ReturnUrl = returnUrl;
int iCookieLifeTime = 10;
if (ModelState.IsValid)
{
var user = await AuthenticateUser(Input.UserName, Input.License, Input.Password, Input.KeepLogged);
if (user == null)
{
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, user.UserName),
new Claim("Password", user.Password ) )
};
var claimsIdentity …Run Code Online (Sandbox Code Playgroud)