Detecting Session Timeout

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. How can I detect if a user's session has timed-out? I'd like to be able
to redirect the user to a specified page in the event of session timeout.

Thanks!
 
You can't.

All you can do on the server, is when there is a request after the timeout,
you can detect it is a new session (either because your session variables
are empty, or because IsNewSession returns true), and redirect then.

Or you can have a countdown running on the client in javascript that
redirects.

The server however cannot know that the client has timed out and send a
redirect down.
 
I have seen some javascript client-side solutions. You may want to look in
the HTML of one of your online account providers, such as a bank or credit
card company, to see an example of a javascript timeout (usualy located in a
..js script file). Otherwise though, there's no real way to know when the
event occurs because the client and server are disconnected the second the
client retrieves the final item for that page.
 
Forgive me if Im wrong but doe'nt the global.asax file have a Session_ONEND
event handler that you can use a redirect within?

Just a thought

Damian
MCP
 
Apologies for my silly remark about global.asax earlier, what you could do is
use this in your page header:

<meta http-equiv="refresh"
content="300;url='checksession.aspx?redirUrl=currentpage.aspx'">

So when the refresh occurs pass your current page across, check the session
state as in the following page load method:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Session("whatever") Then
Response.Redirect("loggedout.aspx")
Else
Response.Redirect(Request.QueryString("redirUrl").ToString)
End If
End Sub

If it exists bounce them back to the original page, if not redirect to a
logged out page.

Thats what my banks uses by the look of it.

Easy Peasy.

Damian
MCP
 
Hi.

Doesn't the action of posting to checksession.aspx actually keep the
session itself alive, voiding the test to begin with?
 
Back
Top