Click here to Skip to main content
16,016,605 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I want to trigger session time out and browser close event as a user log off event,
Is there way to capture this events.
Posted
Comments
Joezer BH 21-Jan-13 5:57am    
Hi tkkf87

More details please,
log off from what? client side? server side? technology?

Cheers,
Edo
tkkf87 21-Jan-13 7:00am    
Client Side session time out is triggered by server side.
Simply administrator wants to know who are the current login users with their ip address.

1 solution

Hi Tkkf87,

I think I understand your question from the comments thread above,

You can add a Javascript timer on the client side that will send an event on the background to the server, the timer can be set to 20 minutes (which is the default session timeout in IIS I believe), or any other value of your choice.

The Javascript can send a user id to keep track, which can be the session_id, that could a safe practice.

This way the server can track it's users that have the session ended,
you can also use this event to return some data to the client, like a notification that the session is about to time out and if he\she wants to stay connected then click "You Bet"! you get the picture ...


Cheers,
Edo
 
Share this answer
 
v4
Comments
tkkf87 22-Jan-13 22:59pm    
You are absolutely right, If you have sample code,Could you please share it with me.
Joezer BH 23-Jan-13 1:25am    
Sure, see http://www.w3schools.com/js/js_timing.asp
for sample code on JS SetTimeOut and SetInterval
tkkf87 23-Jan-13 5:15am    
thx,small question raised up upon the implementation among client and server communication,do you have sample of that,
and other thin ,once client close the browser how server knows that since this javascript runs on client side.
Joezer BH 23-Jan-13 5:21am    
Server does not know when a client closes the browser, it's life is only on the user's computer.

you can try some tricks like catching the onPageExit event in JS to notify the server, but they don't always work.

Client initiating a call to the server on JS is simple, example:

function httpGet(theUrl)
{
var xmlHttp = null;

xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
tkkf87 25-Jan-13 0:54am    
don't you have sample project,it will be easy to understand me.

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