wonderful world
wonderful world

Reputation: 11599

How to find and redirect to a page after ASP.NET session has expired?

I have a ASP.NET web forms checkout application which uses session. The session can expire after 5 minutes. If the user clicks a SUBMIT button on a aspx page,

  1. How can find out that the session has expired?
  2. Is there a application level hook available where I can redirect the user to a page saying your session has timed out and start the checkout process again.

Upvotes: 1

Views: 87

Answers (1)

kman
kman

Reputation: 2257

Because the session lives on the server, all you can really do clientside is set up a timer and try to keep it in sync with the server as best you can. That way you can have code clientside that redirects to your timeout page when your timer (and hopefully) session on the server expire. It can be a challenge keeping your clientside timer in sync though, because you have to consider that ajax operations/partial postbacks/etc reset the server session, so therefore they have to reset your clientside timer too.

Be advised there's no 100% perfect way of doing this. Because of things beyond your control like network latency, the user's PC, etc. - the possibility will always exist that your clientside timer can/will likely be a second or two off from the server session.

I actually wrote a control for this very purpose a few years ago if you want to take a look. It makes implementing this almost plug and play.

Upvotes: 1

Related Questions