tags:

views:

10

answers:

1

Hi All,

I want to know no. of active users on my website with sessionstate set as sqlserver.

And what if a person closes his browser then how to maintain the user count?

Any help appreciated.

Thanks in advance

A: 

What web server code are you using? If you are using ASP.NET, you can increment a variable in Session_Start in your Global.asax file, then write that variable to SQL Server when your web application shuts down in Application_End. Make sure you lock the variable as two threads may be accessing the variable at the same time if two simultaneous connections come in. Not sure if this answers your question. I see you have the word "active" users. If that means ones that are currently on, you can decrement the counter in Session_End. Then, sometime after the user closes the browser, that user's session will time out. You can't decrement right when they close the browser as your web server will have know way of knowing that.

skaz
Thanks 4 your reply but Session_End doesn't get fired when sessionstate is set to sqlserver.
Hitesh