Logout user after inactivity in asp.net core

不想你离开。 提交于 2019-12-24 00:27:46

问题


I am new to asp.net core. I am trying to implement User Logout after being inactive for a period of time. Can someone suggest guide/tutorial or explain how to implement this using asp.net core 2.0 and MySql instead of Entity Framework.


回答1:


After configuring your identity in the services using AddIdentity or AddDefaultIdentity you can configure your cookie ExpireTimeSpan

You could read Cookie Settings block in the linked article.

services.ConfigureApplicationCookie(options =>
{
    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
    options.LoginPath = "/Identity/Account/Login";
    options.SlidingExpiration = true;
});

ExpireTimeSpan is the TimeSpan after which the cookie will expire. SlidingExpiration will instruct the handler a new cookie with new expiration time.

Here documentation:

Summary: The SlidingExpiration is set to true to instruct the handler to re-issue a new cookie with a new expiration time any time it processes a request which is more than halfway through the expiration window.



来源:https://stackoverflow.com/questions/52025491/logout-user-after-inactivity-in-asp-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!