how come i never pass through Session_End(..) in global.asax

F

Franck

Hello,
I'm trying to count the number of current user that way


public class Global : System.Web.HttpApplication
{
public static int nbUsers;
protected void Application_Start(Object sender, EventArgs e)
{
nbUsers = 0;
}
protected void Session_Start(Object sender, EventArgs e)
{
nbUsers++ ;
}
protected void Session_End(Object sender, EventArgs e)
{
nbUsers-- ;
}
....
}
}

but i never pass through the Session_End event
even if I call
Session.Abandon();

Am i Missing anything?
 
B

Brock Allen

If you're saving Session out of proc (NT State Server or SqlServer) is won't
get called. Also, you should use Interlocked.Increment and Interlocked.Decrement
to modify the nbUsers in a thread-safe manner. As it stands now you're code
is not thread safe.
 
S

S. Justin Gengo

The default session timeout is 20 minutes. The web server has no way of
knowing when a client disconnects. So the event will only be fired when the
timeout is reached which is 20 minutes after the server was last connected
to by the client. Have you reset the timeout so it will fire while you're
still debugging?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo

Franck,

Session.Abandon is a method you can call to cause a session to end. After
calling Session.Abandon the Session_End event will be fired.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top