身份 Cookie 一段时间后无法读取

问题描述 投票:0回答:1

我的问题仅在我发布的网站上有效,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 问题吗?感谢您的回答。

c# asp.net-mvc asp.net-core
1个回答
0
投票

我通过添加这个来解决这个问题

builder.Services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromHours(12);
});

至 Program.cs

顺便说一句,这与国际空间站有关。

© www.soinside.com 2019 - 2024. All rights reserved.