What Event Occurs When Someone Leaves Your Web Site?

R

Ross Culver

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
 
R

Ross Culver

Thanks, Juan.

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

Ross
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

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

Mark Rae

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

Guest

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

Ross Culver

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
 
G

Guest

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
 
L

Laurent Bugnion, MVP

Hi,
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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top