tags:

views:

141

answers:

2

i am developing chat application using .net, here i have to refresh the online users periodically, is there any way please suggest me.

now i am getting user name once the user is logged in, and i am removing the user once he press the logout button, its ok and working fine, but some users just close their browser its not possible for me to identify whether he is in online or not, any help will be appreciated.

+1  A: 

You can use some client side notification mechanism using stuff like AJAX (or ASP.NET AJAX). Have the client notify the server every 1-2 minutes to send a "I am alive" signal.

Moron
+2  A: 

For a web app, Have a look at the Asp.NET AJAX Timer control (MSDN)

Also, see the JavaScript BODY onUnLoad event. It is fired when a browser window is closed or the user navigates away by changing the address bar URL or by clicking something etc.

For a form app, Have a look at the various timer controls

Vaibhav Garg
Wouldn't onUnLoad be fired if the page is refreshed? Would be funny if the user refreshes the page and gets logged out! :) Anyway, +1 for the Ajax timer control link.
Moron
yeah didn't think of that. there are some ugly methods to handle that too, though I wouldn't use it. See http://bytes.com/topic/javascript/answers/146991-onunload-action Interesting once i got thinking, Better option would be to set the expire of the logged in user's auth cookie to 2 minutes after receiving a call from onUnLoad and in the Onload or in global.ashx move the expiration forward. so something along those lines would do.Still, the best option would be a 'heartbeat' timer that keeps the user logged in via 'sliding expiration' auth mechanism.
Vaibhav Garg