Detecting Session and/or Authentication Timeout

I have an ASP.NET application which is configured for Forms-based Authentication and has a simple Login.aspx page.  If a user's session or authentication times out, clicking on any of the application's links takes them immediately to the Login page.  This is fine, I can always adjust the timeout values if it gets too annoying.

However, I would like to display a message telling them what happened ("Sorry, your session timed out.  Please log in again.") because I'm sure there will be some (many?) users scratching their heads when this happens.  Is there a way to detect that the login.aspx page was invoked because of a timeout as opposed to a user loging in for the first time?
michaelrendaAsked:
Who is Participating?
 
dumbluckCommented:
Sure, save a session cookie in the browser. It should exist for as long as the browser is open and expire when the browser closes (the default when no Expires timespan is set).
0
 
michaelrendaAuthor Commented:
This works pretty well except when the user navigates away from the site and then returns.  Because the session cookie is still present, you can't tell the difference between this situation and a session timeout.  Still, it works 90% of the time
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.