Jui Test Jui Test - 4 months ago 14
Javascript Question

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');
}

Answer

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);