我有一个模拟测试页面(无需身份验证)并将用户选择数据存储在会话变量中,并在结果页面上从这些会话中检索数据。会话超时设置为 20 分钟,滑动到期为真。有时用户空闲超过 20 分钟(默认超时)。我只想在会话超时并重定向时显示警报。我愿意使用 javascript、jquery 或 asp.net c#。我已经看到类似的问题和答案尝试过 Global.asax 会话结束和 jquery 解决方案,但似乎没有一个对我有用。任何机构都可以根据我的要求给我一个例子吗?谢谢
问问题
2124 次
3 回答
1
http://www.codeproject.com/Articles/227382/Alert-Session-Time-out-in-ASP-Net http://www.codeproject.com/Articles/24669/JavaScript-to-Show-Session-Timeout -柜台
我遇到了类似的问题我尝试了这两个链接
我希望这会对你有所帮助... :)
于 2013-11-01T12:21:12.170 回答
1
这对我来说非常有用
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
//It appears from testing that the Request and Response both share the
// same cookie collection. If I set a cookie myself in the Reponse, it is
// also immediately visible to the Request collection. This just means that
// since the ASP.Net_SessionID is set in the Session HTTPModule (which
// has already run), thatwe can't use our own code to see if the cookie was
// actually sent by the agent with the request using the collection. Check if
// the given page supports session or not (this tested as reliable indicator
// if EnableSessionState is true), should not care about a page that does
// not need session
if (Context.Session != null)
{
//Tested and the IsNewSession is more advanced then simply checking if
// a cookie is present, it does take into account a session timeout, because
// I tested a timeout and it did show as a new session
if (Session.IsNewSession)
{
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out (can't use the cookie collection because even on first
// request it already contains the cookie (request and response
// seem to share the collection)
string szCookieHeader = Request.Headers["Cookie"];
if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
ScriptManager.RegisterStartupScript(this, this.GetType(), "Redirect", "alert('Your session has timed out due to inactivity. Please start the test again'); window.location.reload()", true);
}
}
}
于 2013-11-01T23:23:13.510 回答
0
idleTime = 0;
$(document).ready(function () {
var idleInterval = setInterval(timerIncrement, 5000);
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime >12 ) { //60 secs
alert("session expired");
window.location.href="a3.html";
}
}
此编码有助于会话超时并在警报后60secs
重定向到另一个页面
于 2014-03-06T06:52:42.890 回答