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

C# 使用PasswordSignInAsync登录时如何更改cookie过期时间?,c#,asp.net-core,identityserver4,asp.net-core-identity,asp.net-core-3.1,C#,Asp.net Core,Identityserver4,Asp.net Core Identity,Asp.net Core 3.1,使用以下代码登录时如何更新Cookie过期时间 var result = await _signInManager.PasswordSignInAsync(userName, password, isPersistent, lockoutOnFailure); 我可以和SingInAsyn一起使用 var authProps = new AuthenticationProperties { IsPersistent = isPersistent, ExpiresUt

使用以下代码登录时如何更新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方法

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);
}
public override async Task SignInWithClaimsAsync(ApplicationUser用户、AuthenticationProperties AuthenticationProperties、System.Collections.Generic.IEnumerable附加声明)
{
if(authenticationProperties!=null&&authenticationProperties.IsPersistent)
{
authenticationProperties.ExpiresUtc=DateTimeOffset.UtcNow.AddMinutes(30);
}
wait base.signiWithClaimsAsync(用户、身份验证属性、附加声明);
}

如果您认为这可能会对您有所帮助,请检查问题和答案以下答案是否解决了您的问题?@Rena,没有