why does the amount of visitors not decrease?

C

Chris

Hi,

i want to get the amount of visitors online.
I did this in global.asax

I tested it by opening several browser sessions.
The amount increases, but never decreases, when i close some browsers.
I have heard of 'session.abandon' but have no idea where to put it (not in
Sub Session_End because it's not fired)
I don't want to use the session.timeout.

My web.config doesn't contain any session state of any kind.

Thanks for hints
Chris


Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("visitors") = 0
End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("visitors") = Application("visitors") + 1
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Application("visitors") = Application("visitors") - 1
End Sub
 
M

Mark Rae

Session_End fires when the session ends.

Closing the browser does *not* cause the session to end - this a very common
misconception.

If you want the number to decrease, you will have to force Session_End to
fire by calling Session_Abandon() - the usual way to achieve this is to have
some sort of "Log Out" button, but there is nothing you can do if the user
simply closes their browser...
 
C

Chris

Thanks for replying ..

Where have i do put that Session.abandon?
I mean: in which event (Page_UnLoad ?)
Thanks
 
M

Mark Rae

Where have i do put that Session.abandon?
I mean: in which event (Page_UnLoad ?)

You seem to be getting a bit confused with how ASP.NET pages work...

Page_Unload fires just after the page has been rendered into HTML and
streamed down to the client, not when the user closes the page:
http://msdn2.microsoft.com/en-us/library/ms178472.aspx


Do you have on-line banking? If so, then that website will (almost)
certainly have a "Log Out" button or hyperlink which they encourage you to
click rather than just closing your browser or moving to a different site -
the Session_Abandon() method goes there...

There is no way whatsoever for ASP.NET to know that a user has closed their
browser...
 
C

Chris

Ok, thanks again

Mark Rae said:
You seem to be getting a bit confused with how ASP.NET pages work...

Page_Unload fires just after the page has been rendered into HTML and
streamed down to the client, not when the user closes the page:
http://msdn2.microsoft.com/en-us/library/ms178472.aspx


Do you have on-line banking? If so, then that website will (almost)
certainly have a "Log Out" button or hyperlink which they encourage you to
click rather than just closing your browser or moving to a different
site - the Session_Abandon() method goes there...

There is no way whatsoever for ASP.NET to know that a user has closed
their browser...
 

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,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top