vendredi 31 juillet 2015

Session Time Out Pop Up

I have to show session timeout pop up (MVC 4.0).

It is working with single page, but when I put it on _Layout page and open two different/same pages of website in two different tabs then timer is working independently on both pages although my code in on common layout.

CODE:

var timeOutMinutes = 1;
var timeOutSeconds = timeOutMinutes * 60;
var popUpShown = false;
var logOutCalled = false;
$(document).ready(function () {
    setInterval(TimerDecrement, 1000); // Call Every Second

    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        if (!popUpShown) {
            timeOutSeconds = timeOutMinutes * 60;
        }

    });
    $(this).keydown(function (e) {
        if (!popUpShown) {
            timeOutSeconds = timeOutMinutes * 60;
        }
    });

    $("#pnlPopup").css("display", "none");
    $('#pnlPopup').dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        width: 'auto',
        maxWidth: 700,
        height: 'auto',
        fluid: true,
        hide: 'fold',
        show: 'clip',
        position: 'center',
        title: 'Session Expiring',
        dialogClass: "noclose"
    });

    $("#btnYes").click(function () {
        StayLoggedIn();
    });

    $("#btnNo").click(function () {
        LogOut();
    });
});

function StayLoggedIn() {
    // DO STUFF
}

function LogOut() {
    // LOG OUT ACTION
}

function TimerDecrement() {
    if (timeOutSeconds > 0) {
        timeOutSeconds--;
    }
    else {

        if (!logOutCalled) {
            logOutCalled = true;
            LogOut();
        }
        else {
            logOutCalled = true;
        }
    }
    document.getElementById("seconds").innerHTML = timeOutSeconds;
  document.getElementById("secondsIdle").innerHTML = timeOutSeconds;
    if (timeOutSeconds < 50) {
        popUpShown = true;
        $("#pnlPopup").dialog("open");
    }
}

FIDDLE

How can I make the session time out counter sync for all pages of website by using it on layout.

Aucun commentaire:

Enregistrer un commentaire