首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ASP.NET Core中设置会话超时/到期时间?

如何在ASP.NET Core中设置会话超时/到期时间?
EN

Stack Overflow用户
提问于 2019-12-18 09:56:29
回答 1查看 19.4K关注 0票数 5

我正在使用的ASP.NET零版本7的ASP.NET核心,MVC和jQuery项目。

我正在尝试设置会话超时/到期时间,以便在应用程序空闲一段时间时自动从应用程序中注销。有人能告诉我怎么做吗?

在ASP.NET零版本8中,它们在用户管理设置中提供此配置。

EN

回答 1

Stack Overflow用户

发布于 2019-12-18 13:12:02

ASP.NET核心MVC

MVC的会话到期是通过cookie提供的,它独立于ASP.NET核心,独立于ASP.NET零。

调用ConfigureApplicationCookieIdentityRegistrar.Register in Startup.cs

代码语言:javascript
复制
public IServiceProvider ConfigureServices(IServiceCollection services)
{
    // ...

    IdentityRegistrar.Register(services);                  // No change
    AuthConfigurer.Configure(services, _appConfiguration); // No change

    services.ConfigureApplicationCookie(o =>
    {
        o.ExpireTimeSpan = TimeSpan.FromHours(1);
        o.SlidingExpiration = true;
    });

    // ...
}

来自ASP.NET Core v2.2.8 CookieAuthenticationOptions.cs#L30-L36的缺省值

代码语言:javascript
复制
public CookieAuthenticationOptions()
{
    ExpireTimeSpan = TimeSpan.FromDays(14);
    ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
    SlidingExpiration = true;
    Events = new CookieAuthenticationEvents();
}

ASP.NET零(用于ASP.NET核心)

ASP.NET Zero v7.2.0+提供:

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59389438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档