Get the number of sessions going on now.

R

Ray at

Sub Session_OnStart()
Application.Lock
Application("SessionCount") = Application("SessionCount") + 1
Application.Unlock
End Sub

Sub Session_OnEnd()
Application.Lock
Application("SessionCount") = Application("SessionCount") - 1
Application.Unlock
End Sub

In your global.asa.

Ray at work
 
J

Jeff Clark

i love you Ray.

Ray at said:
Sub Session_OnStart()
Application.Lock
Application("SessionCount") = Application("SessionCount") + 1
Application.Unlock
End Sub

Sub Session_OnEnd()
Application.Lock
Application("SessionCount") = Application("SessionCount") - 1
Application.Unlock
End Sub

In your global.asa.

Ray at work
 
R

Ray at

Oh, did you leave them in there again? You know that I hate it when you do
that! Now I'm going to have to iron them all again. >:|

Ray at work

Jeff Clark said:
Ray, take my clothes out of the dryer when you get home please

Randy Rahbar said:
I love you too Jeff. :]

Stop guys.. I'm getting teary eyed.
 
E

Evertjan.

Evertjan. wrote on 13 nov 2003 in
microsoft.public.inetserver.asp.general:
You will need this too, I think:

Sub Application_OnStart
Application("Active") = 0
End Sub


I mean:

Sub Application_OnStart
Application("SessionCount") = 0
End Sub
 
A

Aaron Bertrand - MVP

But it does always fire though (in my experience)...I have used Rays
technique
for over 3 years and at the end of the day, the counter is always zero.

I've seen cases where it never fired. And remember that you're not always
checking the counts at the end of the day. :)
 
R

Ray at

Do you know in what situations it wouldn't fire? I mean, if you go and kill
inetinfo.exe or something, it fire then, but as soon as you did that, you'd
have zero sessions anyway.

Ray at work
 
A

Aaron Bertrand - MVP

Do you know in what situations it wouldn't fire? I mean, if you go and
kill
inetinfo.exe or something, it fire then, but as soon as you did that, you'd
have zero sessions anyway.

I don't know the exact circumstance, but I had a site with a session timeout
of 20 minutes. One time the provider went down, so you couldn't ping the
box from outside (but I was inside, so could see the database, etc). I had
code in session_onEnd that cleaned out sessions from the database, and I had
about 30 active sessions at the time the site went down (easily queried
right after it happened; I was thinking, "oh crap, how many users did that
affect?"). I did a query 10 minutes later, and there were still 12 active
sessions (so 18 of them must have hit session_onEnd). 10 minutes later
(when all of the session_onEnd() calls should have completed), there were
still 5. An hour later, there were still 5. IIS was still running, nothing
had been restarted, etc.

This actually happened the day before I first wrote the "what is wrong with
session_onEnd()?" article. And I had no idea how I would be able to figure
out what was "special" about those 5 sessions; still don't know how I would
differentiate them if it were to happen today. Also, not sure if this is
still possible in the IIS 6.0 world; I think that was IIS 5.0 where I
experienced it.

Watch the new article about tracking sessions (2491) for the SQL Server
methodology mentioned in 2078.
 
R

Ray at

Aaron Bertrand - MVP said:
I don't know the exact circumstance, but I had a site with a session timeout
of 20 minutes. One time the provider went down, so you couldn't ping the
box from outside (but I was inside, so could see the database, etc). I had
code in session_onEnd that cleaned out sessions from the database, and I had
about 30 active sessions at the time the site went down (easily queried
right after it happened; I was thinking, "oh crap, how many users did that
affect?"). I did a query 10 minutes later, and there were still 12 active
sessions (so 18 of them must have hit session_onEnd). 10 minutes later
(when all of the session_onEnd() calls should have completed), there were
still 5. An hour later, there were still 5. IIS was still running, nothing
had been restarted, etc.

Interesting. Perhaps you should get a better server. :p So, in Jeff's
particular circumstance, it wouldn't matter, since the application variables
would be gone anyway, but it certainly does matter if the session_onend
needs to really do something the way yours was.

Ray at work
 
A

Aaron Bertrand - MVP

Interesting. Perhaps you should get a better server. :p

Oh yeah, that was the problem!
So, in Jeff's
particular circumstance, it wouldn't matter, since the application variables
would be gone anyway

I don't follow... can you elaborate? The application variables were not
gone in my scenario... the server was still running, but session_onEnd did
not fire for 5 of the 30 sessions. So, application("SessionCount") =
application("SessionCount") - 1 left application("SessionCount") 5 too high.
And this was NOT corrected when the server came back online, because the
only symptom of that was that users could hit the server again (the server
itself wasn't down; the provider's pipe was down).

Anyway, I updated http://www.aspfaq.com/2491 with a slightly more reliable
method using SQL Server (that still, admittedly, can leave sessions to be
counted as "active" until the timeout, when they really aren't truly
active... but it will never let a failed session_onEnd permanently spoil the
count).
 
R

Ray at

I don't follow... can you elaborate? The application variables were not
gone in my scenario... the server was still running, but session_onEnd did
not fire for 5 of the 30 sessions. So, application("SessionCount") =
application("SessionCount") - 1 left application("SessionCount") 5 too high.
And this was NOT corrected when the server came back online, because the
only symptom of that was that users could hit the server again (the server
itself wasn't down; the provider's pipe was down).

Yeah, never mind. I was reading it that the server went down. So, I guess
what I was saying is if you're using Session_OnEnd to update application
variable and the ~server~ goes down, it doesn't matter about Session_OnEnd
not updating your app variables, since they'll be gone anyway. But if
you're relying on Session_OnEnd to make changes outside of IIS, like update
a database, delete a file, etc., then yeah, it certainly would matter.
Anyway, I updated http://www.aspfaq.com/2491 with a slightly more reliable
method using SQL Server (that still, admittedly, can leave sessions to be
counted as "active" until the timeout, when they really aren't truly
active... but it will never let a failed session_onEnd permanently spoil
the

Nice. That WMI method is hardcore. Good job.

Ray at work
 
A

Aaron Bertrand - MVP

Nice. That WMI method is hardcore. Good job.

Thanks. I guess you can start to imagine the amount of work that went into
PerfHound, and what a ridiculous bargain it is. :)

It's too bad that WMI requires an Administrator account to be useful from
ASP. Though, I suppose it would be trivial to have local VBS scripts update
a database every so often (more often for volatile information like CPU
usage, less often for static information like # of CPUs).

Hey, that gives me an idea...
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top