I am creating a web application using ASP.Net. I am using session in my application.
There is one scenario where I am trying to access session variable through Javascript. It is working fine, when I m accessing it in normal state. But after session expiry, if click on any button, it throws exception and behaves abnormally, resulting in page not found.
Here is the code I am using;
var TransactionID = '<% =((Hashtable)(Session["SessionData"]))["TransactionID "] %>';
if(TransactionID !='')
{
//action
}
I am trying to achieve something like of sort in c#;
String lsStr;
if(null != lsStr)
{
//action
}
Please help me, if anyone knows how to check if session exists or not using javascript.
Thanks in advance.
I would recommend a public property in your code-behind page that does:
To get around the immediate error. If you want a polling mechanism to know when it expires, consider the JS timer countdown/AJAX call to the server idea. There is no way to check session from the client without requesting information from the server.
But, using the property above, when the page posts back, and on the client the transaction ID JS variable would be null, that would be a way of identifying that the Session expired too.
HTH.