Detect session expiry using JavaScript

I was working on a web application using ASP.Net. I was making use session in my application. 
There was one scenario where I was trying to access session variable through JavaScript. It works fine, when session is accessed in normal state ( i.e. session is not expired). But after session expiry, if click on any button, it was throwing an exception and start abnormal behavior, resulting in page not found. 
To tackle with this, I used session handling from JavaScript as;

public string TransactionID
   get { 
        var data = ((Hashtable)(Session["SessionData"])); 
        if (data != null)
           return data["TransactionID "];
           return null;

No comments:

Post a Comment