如何在ASP.NET Core MVC中设置会话超时/到期时间? [英] How to set session timeout / expiry time in ASP.NET Core MVC?

查看:434
本文介绍了如何在ASP.NET Core MVC中设置会话超时/到期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using ASP.NET Zero version 7 of ASP.NET Core, MVC and jQuery project.

我正在尝试设置会话超时/到期时间,以在应用程序空闲一段时间后自动从应用程序注销.有人可以让我知道怎么做吗?

I am trying to set session timeout / expiry time to automatically log out from the application when the application is idle for some time. Can anybody please let me know how to do this?

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

In ASP.NET Zero version 8, they are providing this configuration at User Management settings.

推荐答案

ASP.NET Core MVC

MVC的会话过期由ASP.NET Core通过cookie提供,独立于ASP.NET Zero.

ASP.NET Core MVC

Session expiry for MVC is provided via cookie by ASP.NET Core, independent of ASP.NET Zero.

Startup.cs 中的 IdentityRegistrar.Register 之后调用 ConfigureApplicationCookie :

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 CookieAuthenticationAuthentications.cs#L30-L36 :

public CookieAuthenticationOptions()
{
    ExpireTimeSpan = TimeSpan.FromDays(14);
    ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
    SlidingExpiration = true;
    Events = new CookieAuthenticationEvents();
}

ASP.NET零(对于ASP.NET Core)

ASP.NET Zero v7.2.0 +提供:

ASP.NET Zero (for ASP.NET Core)

ASP.NET Zero v7.2.0+ provides:

这篇关于如何在ASP.NET Core MVC中设置会话超时/到期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆