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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
prabhakaran S
  • 718
  • 1
  • 6
  • 13
  • are you using asp.net membership provider? – th1rdey3 Oct 19 '12 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 – kbvishnu Oct 19 '12 at 18:59

2 Answers2

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.

Community
  • 1
  • 1
kbvishnu
  • 14,760
  • 19
  • 71
  • 101
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.

highwingers
  • 1,649
  • 4
  • 21
  • 39
  • 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. – highwingers Oct 19 '12 at 19:03