我使用 asp.net C# 制作了一個簡單的網路應用程式,并制作了一個代碼來自動從網站注銷并將用戶重定向到會話過期時的登錄頁面,但是我有一個問題,即網站注銷并將用戶重定向到即使用戶處于活動狀態并單擊按鈕并移動滑鼠,登錄頁面也是如此.
這是我結束會話的代碼:
網路配置:
<sessionState timeout="1"></sessionState>
main_page.aspx:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
AutoRedirect();
}
public void AutoRedirect()
{
int int_MilliSecondsTimeOut = (this.Session.Timeout * 6000);
string str_Script = @"
<script type='text/javascript'>
intervalset = window.setInterval('Redirect()',"
int_MilliSecondsTimeOut.ToString() @");
function Redirect()
{
window.location.href='/login.aspx';
}
</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", str_Script);
}
uj5u.com熱心網友回復:
不談應用程式的超時 如何在 web.config 中設定會話超時
在您的 Javascript 中,我認為您需要在 JavaScript 中停止 setInterval 停止 setInterval 呼叫
那么為什么不在 aspx 頁面的 javascript 中使用所有任務,例如
$(document).ready(function(){
ResetTheTimer();
$('body').mousemove(function() { // or other events
ResetTheTimer();
alert('clear!');
});
});
var intervalset ;
var MilliSecondsTimeOut = 12000;
function ResetTheTimer(){
clearInterval(intervalset);
intervalset = window.setInterval(Redirect, MilliSecondsTimeOut );
}
function Redirect()
{alert(1);
//window.location.href='/login.aspx';
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
然后為了使應用程式活著,您也需要一些時間間隔來回發到后面的代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/391428.html
上一篇:接收json作為字串始終為空
