What would be the best way to detect if the SessionState has died in order to send the user to a “Session Expired” page? I’ve successfully configured the app (in Web.config) to do this when the authentication cookie is gone (there’s a setting for that), but so far I haven’t found an effective way to do something similar when the SessionState is gone. The app in question holds some data in the Session, and should present the user with a “Session Expired – Please login again” page if any of them is gone.
So far, the only option I can think of doing it in each of the places I access Session, but this is obviously a less than optimal solution.
Why not include the session check on the masterpage? Any of your session variables will return null if the session has expired. So on
page_loadyou can check any of them and carry out the appropriate action i.e.Response.Redirect. However you say in theWeb.Configyou can check when the authentication cookie is gone, so can you not carry out an action on this?Another method would be to use a HTTP Module which would intercept each request and decide what to do with it. This would be better than my first method and it’ll occur prior to any page processing.