Wednesday, 26 July 2017

logout inactive user asp.net mvc

In layout page placed this code

 <script>
        $(function () {
            $("body").on('click keypress', function () {
                ResetThisSession();
            });
        });

  var timeInSecondsAfterSessionOut = 30; // change this to change session time out (in seconds).
        var secondTick = 0;

        function ResetThisSession() {
            secondTick = 0;
        }

        function StartThisSessionTimer() {
            secondTick++;
            var timeLeft = ((timeInSecondsAfterSessionOut - secondTick) / 60).toFixed(0); // in minutes
        timeLeft = timeInSecondsAfterSessionOut - secondTick; // override, we have 30 secs only

         

            if (secondTick > timeInSecondsAfterSessionOut) {
                clearTimeout(tick);

                window.location = "/home/Logout";
                return;
            }
            tick = setTimeout("StartThisSessionTimer()", 1000);
        }

      if (window.location != "http://localhost:49609/home/Logout")
        {
            alert(window.location);
            StartThisSessionTimer();
        }
    </script>

remember to stop the timer and reset it once its redirected to logout page

No comments:

Post a Comment