Auto logout when user not using website

  By Junaid A   Posted on April-25-2018   722

.Net

Auto logout when user not using website

Problem:

if user is not using website for some time, user sh'd be logout automatically.

Solution:

 

add below code in  "Java Script"


        function idleLogout() {
            var t;
            window.onload = resetTimer;
            window.onmousemove = resetTimer;
            window.onmousedown = resetTimer; // catches touchscreen presses
            window.onclick = resetTimer;     // catches touchpad clicks
            window.onscroll = resetTimer;    // catches scrolling with arrow keys
            window.onkeypress = resetTimer;

            function logout() {
                window.location.href ='/Account/SignOut'; // URL to logout page.;
            }

            function resetTimer() {
                clearTimeout(t);
                var timeOutValue = 240000; //240000 milliseconds = 4 mints = (if sysem remain idle for 5 mints API session is expired.)
               timeOutValue = 60 * 60000; //  60 mints = 1 hour
               // timeOutValue = 1 * 6000; // few secswond

                t = setTimeout(logout, timeOutValue);  

            }
        }


        idleLogout();

By  asifjans    25-Apr-2018 Views  722



You may also read following recent Post

Item Image
What are 3 C
 228
Item Image
what is .net
 463
Submit Post - Article - Ask a Question - Ask an Interview Question - Submit Useful Links