why does the amount of visitors not decrease?

  • Thread starter Thread starter Chris
  • Start date Start date
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
 
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...
 
Thanks for replying ..

Where have i do put that Session.abandon?
I mean: in which event (Page_UnLoad ?)
Thanks
 
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...
 
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...
 
Back
Top