cc@cc.com wrote:
From the popular website At this link:
http://www.w3schools.com/asp/asp_globalasa.asp
I got this code, but it does not work on my server... I can open three
IE browsers and watch the count go to three. Upon closing two, each
having separate sessions (and session ID's of course), the count
remains at three! I'm not looking for alternative ways of doing this:
I'm interested in knowing why the application variable does not get
reduced upon ending the session by closing the browser. Any ideas?
This seems to be a very prevalent misconception.
The session does not end when the user closes his browser. Think about it.
How can the server know when a user closes his browser? Answer: it can't.
HTTP is a stateless protocol. There is no "signal" sent to the server when a
user closes his browser, or navigates to another website. The only way a web
server has of knowing a session is still in use is if it receives requests
for pages with the session ID in the request headers.
There are only two ways a session will end:
1. A Session.Abandon statement is executed
2. The session's timeout period is exceeded, i.e., the server receives no
new requests for pages containing that session id for a longer period of
time than the session's timeout setting.
So, in the scenario you describe above: if your session timeout setting is
at the default value of 20 min., the user count will get adjusted 20 min.
after the user closes his browser.
Aaron describes a way to get a more accurate count of current users using a
database in this article:
http://www.aspfaq.com/show.asp?id=2491
HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"