Asp.net mvc 信号器MVC在用户处于非活动状态时向其发出警报
我有一个客户要求MVC应用程序在用户处于非活动状态58分钟时弹出一个窗口。 他们说,由于未知的原因,这必须在信号机中完成。(现有项目中没有信号机,我必须加入nuget软件包) 我通常使用信号器向多个用户发送消息。Asp.net mvc 信号器MVC在用户处于非活动状态时向其发出警报,asp.net-mvc,signalr,Asp.net Mvc,Signalr,我有一个客户要求MVC应用程序在用户处于非活动状态58分钟时弹出一个窗口。 他们说,由于未知的原因,这必须在信号机中完成。(现有项目中没有信号机,我必须加入nuget软件包) 我通常使用信号器向多个用户发送消息。 你会怎么做 记录用户已触发控制器操作 记录用户处于非活动状态的时间 发送一条消息说他们已经 仅对一个用户处于非活动状态 我通常会在简单的jQuery中这样做 var idleTime = 0; function resetAreYouStillThereCounter() {
你会怎么做
- 记录用户已触发控制器操作
- 记录用户处于非活动状态的时间
- 发送一条消息说他们已经 仅对一个用户处于非活动状态
var idleTime = 0;
function resetAreYouStillThereCounter() {
idleTime = 0;
}
$(document).ready(function () {
$(document).ready(function () {
//Increment the idle time counter every minute.
setInterval(timerIncrement, 60000); // 1 minute
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
resetAreYouStillThereCounter();
});
$(this).keypress(function (e) {
resetAreYouStillThereCounter();
});
});
function timerIncrement() {
idleTime = idleTime + 1;
//If were on the Login page reset the counter
if (top.location.pathname == "/Authentication/Login") {
resetAreYouStillThereCounter();
}
if (idleTime > 57) { // 57 minutes
alert("Hi, you still here?")
}
}
});