我正在使用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>
谢谢和问候
答案 0 :(得分: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);
}
});