Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i subtract the number of current users as soon as i close the browser. I chkd on google but it says that there is no event handler for that...What should i do. Please Help....
Posted

You Can Use Session_Start to Increase number of users and
Session_End Event to decrease the number of user in Global.asax (Global.asax.vb) file in ASP.net

If you don't have this file in your project you can add it using Add New Item - Global Application Class

Here is sample Event for your Global.asax.vb file

VB
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
       ' Code that runs when a new session is started
   End Sub

   Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
       ' Code that runs when a session ends.
       ' Note: The Session_End event is raised only when the sessionstate mode
       ' is set to InProc in the Web.config file. If session mode is set to StateServer
       ' or SQLServer, the event is not raised.
   End Sub
 
Share this answer
 
 
Share this answer
 
The short answer is there is no reliable way. Sessions are handled server side, not client (browser) side.

An unreliable method is to handle the onunload event in javascript and fire back an Ajax call that would inform the server that the browser is closing. This won't work if javascript isn't enabled, if there is a network problem, or if the browser is killed before it gets a chance to send the request.

The correc thing to do is ask yourself: what are you trying to achieve?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900