在asp.net core中不活动后注销用户 [英] Logout user after inactivity in asp.net core

查看:163
本文介绍了在asp.net core中不活动后注销用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是asp.net核心的新手.我试图在一段时间不活动后实施用户注销.有人可以建议指南/教程,也可以解释如何使用asp.net core 2.0和MySql而不是Entity Framework来实现此功能.

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.

推荐答案

在使用AddIdentityAddDefaultIdentity在服务中配置了您的身份之后,您可以配置Cookie ExpireTimeSpan

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

您可以阅读链接文章中的 Cookie设置 块.

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;
});

ExpireTimeSpanTimeSpan,之后cookie将过期. SlidingExpiration将指示处理程序一个具有新到期时间的新cookie.

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

这里的文档:

摘要: 将SlidingExpiration设置为true,以指示处理程序重新发出新的 每次处理请求的Cookie都具有新的到期时间 超过到期窗口的一半.

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.

这篇关于在asp.net core中不活动后注销用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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