Does a Session timeout Generate an event?

D

David Laub

Is it possible to know when an asp.net session has timed out? Is there some
sort of timer event?

Thanks
 
C

CW

Put your code in the

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
End Sub

handler of the global.asax file.

Same as in the ASP classic.
 
A

Alex Papadimoulis

Session_OnEnd() in your global.asax file is called whenever the session
times out (or is abandoned explicitly).

-- Alex Papadimoulis
 
D

David Laub

Thanks - but that just raises what I guess should have been my REAL
question:

Is there a way of detecting a "real" time out - i.e. the user of the web app
still has a page open in his/her browser, but didn't click a post-back for
20 minutes
versus the user explicitly closed the page/browser

what I specifically want is to display an error page on a time out - but if
just put unconditional code in Session_End, I'll have no way of knowing
what's an error and what isn't.
 
A

Alex Papadimoulis

David,

That can only be handled with client-side code. You'll need to use the
SetTimeout Javascript function. You'll probably need a work around to get it
to handle 20+ minutes, since i believe it works in miliseconds. But, that's
not a terrible deal, I'm sure you could figure it out.

--Alex Papadimoulis
 
C

CW

This is how I would do it.

Craft a cookie that expires, say, in 30 minutes (i.e., a non-persistent
cookie that times out later than a session cookie).

If your Session_start even handler, look for this cookie. If it is present,
then it indicates that user has timed out, but haven't closed the browser.

If the cookie doesn't exist, either it is because the user has not posted
back for 30 mins or the user closed browser (which would remove a
non-persistent cookie).

I guess you just have to determine what is an optimum time for the cookie
expiry time in order to distinguish between time-out vs browser closing.

HTH
 

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,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top