在ASP.NET Core 2.1中在服务器端捕获会话超时 [英] Capture Session timeout on Server side in asp.net core 2.1

查看:128
本文介绍了在ASP.NET Core 2.1中在服务器端捕获会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在会话结束事件上做些事情. 我怎样才能参加这个活动? 与此事件类似的内容可能会超时吗?

I need to do something on Session End Event. How can I access this event? anything similar to this event maybe timeout?

推荐答案

ASP.NET Core中处理此问题的唯一方法-在客户端页面加载(在JS代码中)以计划计时器的会话超时和警告即将到期的用户.如果用户响应-ping服务器端(以刷新会话),或将用户重定向到注销页面.您的会话超时可以在Startup类中配置.因此,您需要将相同的值传递给客户端视图,设置一个计时器(假设是20分钟),以便在19分钟后向用户显示模式,同时倒计时1分钟,并显示一个按钮,例如保持在线".当用户单击按钮时-在服务器端进行AJAX调用(Home控制器中的某些Ping操作或类似的操作).

The only way to handle this in ASP.NET Core - on page load on client side (in JS code) to schedule the timer for session timeout and warn the user when it's close to expire. If user responds - ping server side (to refresh the session), or redirect the user to logout page. Your session timeout can be configured in Startup class. So you need to pass the same value to client view, setup a timer (let say it is 20 minutes) to show the modal after 19 minutes to the user with counting down timer for a minute and a button like "Stay Online". When the user clicks the button - do AJAX call to server side (some Ping action in your Home controller, or something like that).

这篇关于在ASP.NET Core 2.1中在服务器端捕获会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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