如何我警告他们的Web会话即将超时用户? [英] How do I warn the user that their web session is about to time out?

查看:148
本文介绍了如何我警告他们的Web会话即将超时用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查绕了解决方案,但我似乎并没有得到任何针对asp.net mvc的。基本上,我正在寻找在那里会话过期之前通知用户一分钟的解决方案。

I've checked around for a solution but I don't seem to get any directed to asp.net mvc. Basically I'm looking for a solution where a user is notified a minute before the session expires.

理想的解决方案将是倒计时的通知,将有选择续约的会话。

The ideal solution will be count down notification that will have an option to renew the session.

如果刷新页面倒数计时器到期未经用户,我需要登录出来。

If the countdown timer expires without the user refreshing the page, I need to log them out.

推荐答案

事情是这样的:

public class YourController : Controller {
	public ActionResult TheAction() {
		ViewData["SessionTimeout"] = Request.Session.Timout;
		ViewData["SessionWillExpireOn"] = DateTime.Now.AddMinutes(Request.Session.Timeout);
		return View(info);
	}
}

和这样的:

<span>Your session will expire: <%= ViewData["SessionWillExpireOn"].ToString() %></span>
<span id="countDown" style="display:none></span>
<script type="text/javascript">
	var sessionTimout = <%= ViewData["SessionTimeout"].ToString(); %>;		
	var approximateStart = new Date();
	var notifyAfter = new Date(approximateStart + (sessionTimout - 1)*60*1000);
	function startCountDown() {
		setTimout(function() {
			var now = new Date();
			document.getElementById('countDown').style.display = 'inline';
			document.getElementById('countDown').innerHTML = "Countdown: " + now.getMinutes();
			if (now >= notifyAfter)
				alert('About to expire...');
		}, 5000);
	}
	document.onload=startCountDown;
</script>

写在记事本查看,所以请检查语法。我不记得确切日期时间的东西,在JS。

Wrote the View in notepad, so please check the syntax. I also don't remember exactly the DateTime stuff in JS.

反正你应该看到的想法。

Anyway you should see the idea.

这篇关于如何我警告他们的Web会话即将超时用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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