全局配置,对所有的 SignInXXXAsync 方法生效#
private void ConfigureApplicationCookie(IServiceCollection services)
{
//// 配置 Identity 登录 Cookie,比如登录过期时间等
//// https://github.com/abpframework/abp/issues/4356#issuecomment-644477874
//services.ConfigureApplicationCookie(options =>
//{
// //options.AccessDeniedPath = "/Identity/Account/AccessDenied";
// //options.Cookie.Name = "YourAppCookieName";
// //options.Cookie.HttpOnly = true;
// options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
// //options.LoginPath = "/Identity/Account/Login";
// //// ReturnUrlParameter requires
// ////using Microsoft.AspNetCore.Authentication.Cookies;
// //options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
// //options.SlidingExpiration = true;
//});
}
在登录时配置#
await SignInManager.SignInAsync(user, new AuthenticationProperties()
{
// 总是记住登录状态,因为不记住的话登录状态是 session 维持的,浏览器关闭后 session 就失效了
// 比如未勾选时过期时间为1天,勾选之后过期时间为5天
// 当 IsPersistent = true 时,identity 才会发送 cookie 到客户端浏览器,才能设置过期时间,false 代表使用 session 维持绘画,在浏览器关闭后 se
IsPersistent = true, //LoginBySmsCodeInput.RememberMe,
ExpiresUtc = DateTime.Now.AddDays(LoginBySmsCodeInput.RememberMe ? 5 : 1),
});