我的问题仅在我发布的网站上有效,Cookie 在本地主机上正常工作。然而,登录网站后,它不会等待它应该等待的 1 天时间。
public static void ConfigureCookie(this IServiceCollection services)
{
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Account/Login";
options.AccessDeniedPath = "/Account/AccessDenied";
options.Cookie = new()
{
Name = "ta_cookie",
HttpOnly = true,
SameSite = SameSiteMode.Lax,
SecurePolicy = CookieSecurePolicy.Always,
IsEssential = true
};
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromDays(1);
});
}
这是我的代码
var result = await _signInManager
.PasswordSignInAsync(user, model.LoginModel.Password,
model.LoginModel.RememberMe, true);
if (result.Succeeded)
{
return RedirectToAction("Index", "Home");
}
我想要一个持续 1 天的会话,就像在本地主机上一样。否则,可以使用cookie,但正如我所说,它会提前结束。
这可能是 cloudflare 问题吗?感谢您的回答。
我通过添加这个来解决这个问题
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromHours(12);
});
至 Program.cs
顺便说一句,这与国际空间站有关。