6

my requirement is bit of complicated . an user is accessing the data base using the web browser, while accessing the data base if the user is closed the active page instead of log out the session - that session needs to be log out automatically. can some one guide me how to make this ? i am used jquery - in the master page.

onbeforeunload - i am getting message leave the page or stay with this page. even i am getting this messages while login and and view the home page too.

2
  • are you using asp.net membership provider? Commented Oct 19, 2012 at 18:30
  • you must put some session time out,and need to check whether the user is active on that window. an eg for this is what they did in gmail(gtalk), it will automatically goes to idle if the browser is idle for a long time. In your case you must clear the session, what internet banking sites does Commented Oct 19, 2012 at 18:59

2 Answers 2

3

This is the sample code

  window.onbeforeunload = function () {
   return 'You want to leave?';
};​​

see demo here

I think its possible to send an ajax request and you can saw your server that the user closed the browser's tab.

Also this a jquery plugin called jquery.idle, which is used to identify if the user is active.

Refer this Detecting idle time in JavaScript elegantly will gives you more idea.

Sign up to request clarification or add additional context in comments.

Comments

0

You man close the browser or navigate to different page within website? If its closing the browser then the session automatically dies.

Also look into global.asax 's sesson_onEnd event.

1 Comment

Http is stateless, so you cant really tell if a browser tab or window is closed. You can reduce the session timeout, or use ajax polling(not easy solution), with ajax script keep checking wether page is alive or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.