Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Check every time if user session is expired in JavaScript [closed]

Check every time if Session has expired and if yes then redirect to home page by using JavaScript such as facebook do if I press ctrl+shift+del then it shows login window. I am using .aspx web pages and using WCF services

like image 951
Shailesh Avatar asked Dec 06 '25 23:12

Shailesh


1 Answers

I do not know if this is the best solution, but here's a solution that will test every 500 milliseconds if the user session has expired

Checker permanently a session variable with "setInterval" function every 500 milliseconds :

    function CheckSession() {
                var session = '<%=Session["username"] != null%>';
                //session = '<%=Session["username"]%>';
                if (session == false) {
                    alert("Your Session has expired");
                    window.location = "login.aspx";
                }
            }

setInterval(CheckSession(),500);

See here : http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/362898/check-for-session-timeout-in-javascript-and-redirect-to-login-page#

like image 195
Mehdi Bugnard Avatar answered Dec 09 '25 14:12

Mehdi Bugnard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!