tags:

views:

41

answers:

2

In ASP.NET, Session_End will be fired when the Session is time out then I can guess the user has left or close the Browser window in this method.

But there is some delay till time out, is there any better solution?

+1  A: 

Since there are many things that can interrupt a user's visit like a lost connection, or a browser crash; you should rely on the the client to tell the server "Hey I am still here." and assume they left when they stop doing so that rather than have the client tell the server they left.

To accomplish this, you can use what's known as the "Heartbeat":
http://ajaxpatterns.org/Heartbeat

You can tweak the heartbeat interval so the effect can be more immediate. Doing that you can also tweak what you consider "user activity." Relying on functions fired onunload will cause users who left their computer but didn't close their browser window appear to be "active."

NullUserException
Interesting technique (first ive heard). +1
RPM1984
A: 

There's really no completely reliable method to accomplish this. But take a look at the unload event in jQuery, it may be useful to you.

Jakob Gade
As I said in my answer, this will cause users who left their windows open (but are no longer active) appear to "active" to the server.
NullUserException