How can I make sure that Session_End is called when the user closes the browser?

A

Annie

Hi guys,

I just want to do some clean up in the Session_End at Global.aspx.

However, if the user closes the browser window that event is not fired.

how can I call explicity protected void Session_End(Object sender, EventArgs
e)
when the user closes the browser window?



possible at all?



TA
 
J

JIMCO Software

Annie said:
Hi guys,

I just want to do some clean up in the Session_End at Global.aspx.

However, if the user closes the browser window that event is not
fired.
how can I call explicity protected void Session_End(Object sender,
EventArgs e)
when the user closes the browser window?

Not possible. You're working with a connectionless architecture. The
server has no knowledge of when the user closes their browser.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003
 
H

Hans Kesting

Annie said:
Hi guys,

I just want to do some clean up in the Session_End at Global.aspx.

However, if the user closes the browser window that event is not
fired.
how can I call explicity protected void Session_End(Object sender,
EventArgs e)
when the user closes the browser window?



possible at all?



TA

The session does not end when the user closes the browser, but (default)
20 minutes after the last request to the site. (So if he was busy for 30 minutes
reading a single page, the session would have ended).

There is no (reliable) way to detect that the user has closed the browser,
navigated away from the site, or lost his internet connection.

Hans Kesting
 
A

Annie

wow gettting very interesting!
How about catching it in client side using Javascript and something and
passing it to server somehow?
not possible at all?
 
J

JIMCO Software

Annie said:
wow gettting very interesting!
How about catching it in client side using Javascript and something
and passing it to server somehow?
not possible at all?

Sessions use a sliding expiration. That means that as soon as you "pass it
on to the server", you reset your Session expiration, thereby delaying the
execution of Session_End, not expediting it.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003
 
J

JIMCO Software

Annie said:
wow gettting very interesting!
How about catching it in client side using Javascript and something
and passing it to server somehow?
not possible at all?

Hit Send too soon. :)

Of course you could have your browser call a page that calls
Session.Abandon, but you have to remember that there is no way to hook a
client side event ONLY when the browser is closed. It would be impossible
(as far as I can think right off this early in the AM) to detect the browser
closing correctly.

One more thing to add. Session_End is indeterminate. Even if you call
Session.Abandon, you cannot guarantee when Session_End will get called.

--
Jim Cheshire
JIMCO Software
http://www.jimcosoftware.com

FrontPage add-ins for FrontPage 2000 - 2003
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top