How To Detect MVC 3 Session Expiration via JavaScript

后端 未结 1 1585
庸人自扰
庸人自扰 2020-12-12 06:44

I have an MVC 3 site with a session timeout of 2 minutes.

If the user doesn\'t interact with the page within 2 minutes, they should be automatically forwarded to the

相关标签:
1条回答
  • 2020-12-12 07:18
    var checkTimeout;
    
    $(document).ready(function () {
        checkTimeout = setTimeout(checkSession, 900000);
    });
    
    function checkSession() {
        $.ajax({
            url: "/Account/CheckIfSessionValid",
            type: "POST",
            success: function (result) {
                if (result == "False") {
                    window.location = "/Account/LogOff";
                }
            },
            complete: function () {
                setupSessionTimeoutCheck();
            }
        });
    }
    
    function setupSessionTimeoutCheck() {
        clearTimeout(checkTimeout);
        checkTimeout = setTimeout(checkSession, 900000);
    }
    
    0 讨论(0)
提交回复
热议问题