【问题标题】:Different Session Time out .net core Session不同的会话超时.net核心会话
【发布时间】:2019-06-06 19:11:12
【问题描述】:

我正在使用 .net core 2 构建 API 我想为不同的用户更改会话超时。这就像每个人的默认会话超时(24 小时)(我可以从服务配置中完成)。如果有人说“让我保持登录”,那么会话超时将是一个月或更长时间。

但是 .net 核心没有 Session.Current Session 像以前的 .net 版本 我可以在其中更改会话超时值。

-感谢您的帮助

【问题讨论】:

    标签: asp.net-core session-timeout


    【解决方案1】:

    对于默认的 cookie 过期时间,您可以在 Startup.cs 中设置:

    services.ConfigureApplicationCookie(options =>
    {
        options.ExpireTimeSpan = TimeSpan.FromHours(24);
    });
    

    对于那些想要保持登录状态的人,您可以在登录时更改 cookie 过期日期:

    var result = await this.signInManager.CheckPasswordSignInAsync(account, password, false);
    if (result.Succeeded)
    {
        await this.signInManager.SignInAsync(account, new AuthenticationProperties
        {
            ExpiresUtc = DateTime.UtcNow.AddDays(30),
            IsPersistent = true
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-08
      • 2023-02-02
      • 2021-06-28
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2010-12-05
      • 2021-04-26
      相关资源
      最近更新 更多