使用以下代码登录时如何更新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);
答案 0 :(得分:0)
找不到通过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);
}