Detecting Session Timeout

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!
 
M

Marina Levit [MVP]

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.
 
M

Mark Fitzpatrick

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.
 
G

Guest

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
 
G

Guest

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
 
D

djarvis8

Hi.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top