使用 PasswordSignInAsync 登录时如何更改 cookie 过期时间?

How to change cookie expiration time when signin with PasswordSignInAsync?

如何在使用以下代码登录时更新 Cookie 过期时间

var result = await _signInManager.PasswordSignInAsync(userName, password, isPersistent, lockoutOnFailure);

赞可以与 SingInAsyn 一起使用

 var authProps = new AuthenticationProperties
 {
      IsPersistent = isPersistent,
      ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(5)
 };
 await _signInManager.SignInAsync(user, authProps, authenticationMethod);

未找到传递 authenticationProperties 的方法,但下面的代码有效。需要重写 SingInManager 的 SignInWithClaimsAsync 方法class

public override async Task SignInWithClaimsAsync(ApplicationUser user, AuthenticationProperties authenticationProperties, System.Collections.Generic.IEnumerable<System.Security.Claims.Claim> additionalClaims)
{
    if (authenticationProperties != null && authenticationProperties.IsPersistent)
    {
        authenticationProperties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(30);
    }

    await base.SignInWithClaimsAsync(user, authenticationProperties, additionalClaims);
}