2.0: implementing users' counting with global.asax

R

R.A.M.

Please help.
I try to implement counting of apllication users using global.asax
this way:

<script runat="server">
void Application_OnStart(object sender, EventArgs e)
{
Application.Add("U¿ytkownicy", 0);
}
void Application_OnEnd(object sender, EventArgs e)
{
Application.Remove("U¿ytkownicy");
}
void Session_OnStart(object sender, EventArgs e)
{
Application.Lock();
Application["U¿ytkownicy"] =
Convert.ToInt32(Application["U¿ytkownicy"]) + 1;
Application.UnLock();
}
void Session_OnEnd(object sender, EventArgs e)
{
Application.Lock();
Application["U¿ytkownicy"] =
Convert.ToInt32(Application["U¿ytkownicy"]) - 1;
Application.UnLock();
}
</script>

Unfortunatelly it does not work because Session OnStart/OnEnd and even
Application OnStart/OnEnd are called more often than I thought. For
Session_OnEnd/Session_OnStart instance it's sometimes called when
another page is selected from sitemap menu.
Do you know how to programme it?
Thank you very much.
/RAM/
 
B

Bruno Alexandre

that is a glich in your code, because Session.OnStart only fires when a New
Session is required from the user, or everytime that timesout and need to
set a new one

Application_Onstart you need to stop and start the server so that can be
fired

if you do not own the server, just add to the Session_OnStart

if isNumeric(application("howmany")) then
application("howmany") += 1
else
application("howmany") = 0
end if
 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top