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?
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?
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."
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.