Robin Robin - 4 months ago 26
jQuery Question

Logout user from JS function in Layout view

I am using Timeout Dialouge plugin in asp.net MVC web app from https://github.com/rigoneri/timeout-dialog.js for showing a session timeout popup countdown.

In my layout page I have following JS call:

@if (User.Identity.IsAuthenticated)
{
<script type="text/javascript">
$(document).ready(function () { $.timeoutDialog({ timeout: 1200, countdown: 60, logout_redirect_url:'../Account/LogOff', restart_on_yes: false }); });
</script>
}


Notice the "logout_redirect_url:'../Account/LogOff'" part, Account is Controller & LogOff is Action. The countdown timer shows as expected but it does not redirects to LogOff action and reloads the active page again.

Am I doing something wrong here?

Answer

This plugin is 5 years old and no more maintained.

The problem you are experiencing is with the jQuery libraries: if you use the libraries available when this plugin was developed it works well:

$(function () {
  $.timeoutDialog({
    timeout: 1,
    countdown: 5,
    logout_redirect_url: '../Account/LogOff',
    restart_on_yes: false
  });
});
<link rel="stylesheet" href="https://rawgit.com/rigoneri/timeout-dialog.js/master/css/timeout-dialog.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<script src="https://rawgit.com/rigoneri/timeout-dialog.js/master/js/timeout-dialog.js"></script>