Jui Test Jui Test - 1 year ago 48
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 Source

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