public async Task <System.OperatorLoginResult> Login(string username, string password) { var op = _systemUserRepo.GetSystemOperator(username, password); if (op == null) { return(null); } var claims = new List <Claim> { new Claim(ClaimTypes.Name, op.Name), new Claim("UserID", op.OperatorID) }; foreach (var roleName in op.RoleNames) { claims.Add(new Claim(ClaimTypes.Role, roleName)); } var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); ClaimsPrincipal user = new ClaimsPrincipal(claimsIdentity); await _httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user, new AuthenticationProperties() { IsPersistent = true, // 持久Cookie和绝对到期时间 AllowRefresh = true // 允许有效时间刷新 // ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(60), // 有效时间 }); return(op); }