我使用setTimeout來調用MVC操作來嘗試保持用戶表單身份驗證的活動狀態。使用Javascript setTimeout調用MVC操作來保持活動表單身份驗證
當我正常調用此代碼(即不使用setTimeout)時,它會保持表單身份驗證活着。
在setTimeout中調用時,它不會。
我的問題是爲什麼當通過setTimeout調用時不工作?
$(document).ready(function() {
DoKeepAlive(); //simple test when page loads....does keep forms auth alive
});
var timeout= 0;
timeout= setTimeout(validationPrompt, 2 * 60 * 1000);
function validationPrompt() {
var answer = confirm("Your session will timeout in less than a minute. Click OK to stay logged in, and reset the timout period.")
if (answer) {
DoKeepAlive(); //when called in here by setTimeout, does NOT keep forms auth alive
//re-set the 10 minutes count
clearTimeout(timeout);
timeout= setTimeout(validationPrompt, 2 * 60 * 1000);
}
else {
var URL = "<%= Url.Content("~/Account/Logoff") %>"
window.location = URL;
}
}
function DoKeepAlive(){
var URL = "<%= Url.Content("~/Account/ValidateAuthentication") %>"
$.post(
//"../../Account/ValidateAuthentication",
URL,
function(data) {
}
);
}
缺少一些代碼?什麼是「promptUserTimeoutId」?另外,爲什麼你將「timeout」設置爲「validationPrompt」函數? – 2011-06-10 07:43:17
對不起亞歷杭德羅,我試圖分類我的代碼,並把它弄得一團糟 - 現在應該更清楚了嗎? – ozz 2011-06-10 08:36:23