Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether session is null or not in javascript?

How to check whether session is null or not in javascript?It is right way?

if ('<%=Session["Time"] == null%>')
{
    alert('null session');
}
like image 950
Jui Test Avatar asked Dec 19 '25 06:12

Jui Test


1 Answers

Here's a solution that will test every 500 milliseconds if the user session has expired.

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

setInterval(CheckSession(),500);
like image 129
HenryDev Avatar answered Dec 20 '25 18:12

HenryDev