Asp.net - 会话超时(关闭确认消息)

时间:2012-09-03 07:48:24

标签: asp.net

为会话超时实现了这个工作正常:

var sessionTimeoutWarning = "1";
var sessionTimeout = "2";
var timeOnPageLoad = new Date();
var sessionWarningTimer = null;
var redirectToWelcomePageTimer = null;
//For warning
var sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
//To redirect to the welcome page
var redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()', parseInt(sessionTimeout) * 60 * 1000);

//Session Warning
function SessionWarning() {
    var minutesForExpiry = (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
    //var minutesForExpiry = "1";
    var message = "Your session will expire in another " + minutesForExpiry + " mins. Do you want to extend the session?";

    //Confirm the user if he wants to extend the session
    answer = confirm(message);

    //if yes, extend the session.
    if (answer) {

        //Clear the RedirectToWelcomePage method
        if (redirectToWelcomePageTimer != null) {
            clearTimeout(redirectToWelcomePageTimer);
        }

        var currentTime = new Date();
        var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes() + parseInt(sessionTimeout));
        if (Date.parse(currentTime) > timeForExpiry) {
              alert("Session expired. You will be redirected to welcome page");
            window.location = "../login.aspx";
        }
        else {
            timeOnPageLoad = new Date();
            sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
            redirectToWelcomePageTimer = setTimeout('RedirectToLoginPage()', parseInt(sessionTimeout) * 60 * 1000);
        }
    }
    else {
        timeOnPageLoad = new Date();
        sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
        redirectToWelcomePageTimer = setTimeout('RedirectToLoginPage()', parseInt(sessionTimeout) * 1);

    }

}

//Session timeout
function RedirectToLoginPage() {
    window.location = "../login.aspx";
}

查询:当确认消息出现时,我们如何跟踪/启用如果用户未在5分钟内点击该确认消息,那么我想自动关闭它并显示会话已过期的新弹出窗口。

请告知

1 个答案:

答案 0 :(得分:0)

打开警报框后,您无法控制警报框。您最常做的是在显示警告框5分钟后刷新页面。因此,您可以在显示警告框后编写setTimeout,然后重定向页面,您可以在其中显示该会话已过期的弹出窗口。