If you use Session variables in your Active Server Pages web application, you've most likely noted that screwy things can happen if the Session expires and the user accesses the page. For example, if you let the user choose the background color of the HTML page, as long as the Session is active, he or she will see the background in the color specified. Say that this web surfer leaves his machine, and returns later, after the session has expired. When he tries to access your web page, the background color will be the default color rather than the one he specified. Maintaining Session state is not an impossible task. Below you will find an explanation from a Mr. Michael Rothwell, as he explains how to maintain Session state:
How to Maintain your Session State:
The initial question was posed:
Question : How do I ensure that a visitor to my site...who has left their computer idle causing session vars to be lost, doesn't get an awful asp error when they try to proceed to the next page in the app (without the session variables needed for said page to work !) If my timeout is set at 20 mins, can I force a redirect at 19:59? Is there a better way to accomplish what I'm trying to do? Please help.
Michael Rothwell responded with this answer:
The maintenance of a Session state is not an intuitively easy task. In fact, this is one reason why many developers discourage the use of Session variables (be sure to check out the article Pros and Cons of Session Variables). The task, however difficult, is not impossible, although a little hand-waving does seem necessary.