0

我正在使用 Timeout-Dialog.js ( https://github.com/rigoneri/timeout-dialog.js?next=%2Ftimeout-dialog.js%2F&timeout=t ),它按预期工作正常。我将 javascript 放在 _Layout.cshtml 中。不知何故,当会话即将到期时,即使当前视图是登录屏幕,也会提示 TimeOut 警告对话框。我可以知道应用超时代码的最佳位置是什么吗?

已放在 _Layout.cshtml 中的代码:

<script type="text/javascript">

    $(function () {
        var timeout = 1800000; //30 minutes idle
        $(document).bind("idle.idleTimer", function () {
            // function you want to fire when the user goes idle
            $.timeoutDialog({ timeout: 1, countdown: 60, logout_redirect_url: 'http://localhost:57850/EMAP/Account/Login', restart_on_yes: false });

        });
        $(document).bind("active.idleTimer", function () {            
            // function you want to fire when the user becomes active again
        });
        $.idleTimer(timeout);
    });

</script>

谢谢并恭祝安康

4

1 回答 1

0

为您的登录视图使用单独的布局,或者在运行代码之前检查操作名称:

$(function () {
    if("@ViewContext.RouteData.GetRequiredString("action")" != "MyActionName") {
        var timeout = 1800000; //30 minutes idle
        $(document).bind("idle.idleTimer", function () {
            // function you want to fire when the user goes idle
            $.timeoutDialog({ timeout: 1, countdown: 60, logout_redirect_url: 'http://localhost:57850/EMAP/Account/Login', restart_on_yes: false });

        });
        $(document).bind("active.idleTimer", function () {            
            // function you want to fire when the user becomes active again
        });
        $.idleTimer(timeout);
    }
});
于 2013-12-19T02:08:58.030 回答