如何在ASP.NET Core MVC中设置会话超时/到期时间? [英] How to set session timeout / expiry time in 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:
- 对于MVC:前端配置和倒数模式.
文件:aspnet-core-mvc/v7.2.0/Features-Mvc-Core-Tenant-Settings#user-management - 对于Angular:通过令牌,前端配置和倒数模式实现会话超时.
文件: aspnet-core-angular/v7.2.0/Features-Angular-Tenant-Settings#user-management
这篇关于如何在ASP.NET Core MVC中设置会话超时/到期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!