【问题标题】:ASP.NET Core Identity session expires sooner than it is configured to happenASP.NET Core Identity 会话的到期时间早于配置发生的时间
【发布时间】:2017-09-12 04:24:18
【问题描述】:

所以在我的应用程序中,我将身份配置为:

services.ConfigureApplicationCookie(cfg =>
            {
                cfg.Cookie.Name = "application_ms_state";
                cfg.Cookie.Expiration = TimeSpan.FromDays(1);
                cfg.SlidingExpiration = true;
            });

但到期时间几乎是 20 分钟。有人能解释一下吗?

【问题讨论】:

  • 也许这会有所帮助:stackoverflow.com/questions/37086645/…
  • 我已经直接将 signInManager.SignInAsync 与 IsPersistent = true 一起使用,但仍然没有运气!
  • 您在 Startup.cs 中设置的 ExpireTimeSpan 有什么? (在链接的帖子中提到)
  • 我正在使用身份 2.0.0,它的配置方式与我在 question.in v 2.0.0 中发布的其他方式相同,它是 cfg.Cookie.Expiration
  • 在你上面提到的 services.ConfigureApplicationCookie(cfg => 方法中直接加入 IsPersistent = true 怎么样?

标签: c# asp.net-core asp.net-identity


【解决方案1】:

感谢this answer 背后的人,经过几天的搜索后,我发现问题在于,每 30 分钟检查一次身份(默认情况下,它是可配置的),以查看已打勾的身份验证是否有效,因此它会检查是否实现UserStore<> 的类正在实现IUserSecurityStampStore (UserManager.SupportsUserSecurityStamp) 。由于我正在实现 IUserStroe 的 MembershipService 类没有实现 IUserSecurityStampStore<> 因此在 30 分钟间隔后我最终会得到无效的安全标记和 == SignOut 的空主体。

查看github issue 以获取提到的代码 sn-ps 的参考。

【讨论】:

    【解决方案2】:

    阅读文档 cmets。 https://github.com/aspnet/Security/blob/a53bf093a7d86b35e019c80515c92d7626982325/src/Microsoft.AspNetCore.Authentication.Cookies/CookieAuthenticationOptions.cs#L147 ExpiresTimeSpan 和 Expiration 控制不同的东西。 ExpiresTimeSpan 是用于滑动过期的。

    【讨论】:

    • 我申请了ExpiresTimeSpan 并等待结果。如果我在该时间跨度之后没有注销,我会在 40 分钟左右后将你标记为答案:D。
    • 我将您标记为答案,因为它更有可能是常见问题,但我会为那些遇到类似问题的人发布我自己的答案。提前感谢您坚持问题。
    猜你喜欢
    • 2012-07-07
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多