By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,133 Members | 1,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,133 IT Pros & Developers. It's quick & easy.

What Event Occurs When Someone Leaves Your Web Site?

P: n/a
I need to ensure that session variables are removed whenever someone leaves
my web site. My understanding is that this should be happening
automatically with the session mode set to InProc. But it's not. Every
machine I'm testing this on does the same thing, but then again, everyone is
using Internet Explorer 7.0 with multiple tabs active.

Also, this problem just popped up, probably due to a change I've made, but I
don't have a clue what that might have been.

Thanks.

Ross

Jun 14 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Thanks, Juan.

So Mark is correct, that under these conditions, the only way to clear the
session variables is with the session timeout?

Ross
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:eZ**************@TK2MSFTNGP04.phx.gbl...
re:
!What Event Occurs When Someone Leaves Your Web Site?

None.

You can detect when someone closed a page ( body onunload="javascrip..." )
or ( window.onunload )
...but you can't detect when someone leaves your website.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Ross Culver" <rc*****@warrenalloy.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>>I need to ensure that session variables are removed whenever someone
leaves
my web site. My understanding is that this should be happening
automatically with the session mode set to InProc. But it's not. Every
machine I'm testing this on does the same thing, but then again, everyone
is
using Internet Explorer 7.0 with multiple tabs active.

Also, this problem just popped up, probably due to a change I've made,
but I
don't have a clue what that might have been.

Thanks.

Ross


Jun 14 '07 #2

P: n/a
I concur with Juan and Mark. Due to the stateless nature of the web,
session timeout is the most reliable way to determine somebody has left your
site.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"Ross Culver" <rc*****@warrenalloy.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I need to ensure that session variables are removed whenever someone leaves
my web site. My understanding is that this should be happening
automatically with the session mode set to InProc. But it's not. Every
machine I'm testing this on does the same thing, but then again, everyone
is
using Internet Explorer 7.0 with multiple tabs active.

Also, this problem just popped up, probably due to a change I've made, but
I
don't have a clue what that might have been.

Thanks.

Ross
Jun 14 '07 #3

P: n/a
"Ross Culver" <rc*****@warrenalloy.comwrote in message
news:OB**************@TK2MSFTNGP04.phx.gbl...
So Mark is correct, that under these conditions, the only way to clear the
session variables is with the session timeout?
Yes he is.

ASP.NET apps (like all HTTP websites) work on the HttpRequest / HttpResponse
architecture.

The client browser sends a request to the server, the server process the
request, the server sends back a response.

The server knows ABSOLUTELY NOTHING WHATSOEVER about what happens on the
client machine after that until / unless the client sends another request.

If the client machine doesn't send another request to the server because
maybe the user navigated to another website or just closed the browser, the
server has no way of knowing...

If you have on-line banking, your bank will almost certainly have advised
you to click on the "Log Out" button (or whatever) as soon as you've
finished checking your account - behind the "Log Out" button will be the
code which calls Session.Abandon() etc...

But if you don't click on the "Log Out" button, that's just too bad - your
session will eventually timeout...

This really is just the way it is...
--
http://www.markrae.net

Jun 14 '07 #4

P: n/a
On Jun 14, 10:27 pm, "Ross Culver" <rcul...@warrenalloy.comwrote:
So when does the page.dispose event take place? I'd like to call the
session.abandon, but I don't know when. I can't call it in the page.unload
since that defeats the purpose of having it in the first place. If I
understand you correctly, you're saying that the only way to clear the
session variables under the conditions I've describe is with the session
timeout, correct?
Disposed is the last event on the page occured when a it is released
from memory.

If you call Session.Abandon within the page then the session will be
closed even user doesn't leave your site. So, it doesn't help you.

I need to ensure that session variables are removed whenever someone leaves
my web site.
Why do you need to remove it like that?

Just make a timeout as it is already suggested, and expired session
will be removed automatically.

Jun 14 '07 #5

P: n/a
The only reason this is an issue is because I have a gridview that populates
as a result of a user search. The testing team has commented that if they
perform a search, then navigate to some other site and then type the search
page url back into the address line, the result set previously presented
comes up instead of the default view (I have the gridview on a multiview
component). They want the default page to be presented instead of the
gridview. Before you ask, there's a reason why the page is coded to
recreate the grid results upon returning to the page due to the fact that a
user can make a selection from the grid, be directed to a new page and then
return back to the same grid result to continue their search.

Any way, while this is less than perfect, it's certainly not a deal breaker.

Thanks to all for you comments and info.

Ross
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@z28g2000prd.googlegr oups.com...
On Jun 14, 10:27 pm, "Ross Culver" <rcul...@warrenalloy.comwrote:
>So when does the page.dispose event take place? I'd like to call the
session.abandon, but I don't know when. I can't call it in the
page.unload
since that defeats the purpose of having it in the first place. If I
understand you correctly, you're saying that the only way to clear the
session variables under the conditions I've describe is with the session
timeout, correct?

Disposed is the last event on the page occured when a it is released
from memory.

If you call Session.Abandon within the page then the session will be
closed even user doesn't leave your site. So, it doesn't help you.

>I need to ensure that session variables are removed whenever someone
leaves
my web site.

Why do you need to remove it like that?

Just make a timeout as it is already suggested, and expired session
will be removed automatically.

Jun 14 '07 #6

P: n/a
On Jun 14, 11:43 pm, "Ross Culver" <rcul...@warrenalloy.comwrote:
The only reason this is an issue is because I have a gridview that populates
as a result of a user search. The testing team has commented that if they
perform a search, then navigate to some other site and then type the search
page url back into the address line, the result set previously presented
comes up instead of the default view (I have the gridview on a multiview
component). They want the default page to be presented instead of the
gridview. Before you ask, there's a reason why the page is coded to
recreate the grid results upon returning to the page due to the fact that a
user can make a selection from the grid, be directed to a new page and then
return back to the same grid result to continue their search.
What I can suggest here is to use a postback to navigate users between
the pages

if (Page.IsPostBack) {
recreate_grid_results();
}
// else do nothing (default view)

It would help to avoid this:
perform a search, then navigate to some other site and then type the search
page url back into the address line, the result set previously presented
comes up instead of the default view
So, instead of simple hyperlinks use the LinkButton Control

Jun 15 '07 #7

P: n/a
Hi,

Juan T. Llibre wrote:
re:
!What Event Occurs When Someone Leaves Your Web Site?

None.

You can detect when someone closed a page ( body onunload="javascrip..." ) or ( window.onunload )
Even that is unreliable. If JavaScript is deactivated, no such event.
Also, in some browsers, these onunload events have low priority and may
very well never be thrown.
...but you can't detect when someone leaves your website.
Actually, the onunload event is also raised when the user leaves the
website. It is raised everytime that the current page is unloaded, which
means also when it is refreshed. This is why it's very difficult (and
useless, see above) to use these events to notify the server about the
state of the web client.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jun 15 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.