简体   繁体   中英

Call Page Method on Browser Close

I need to call a pagemethod when the user closes the browser or active tabs of a particular ASP.NET 4.5.1 website, tried onbeforeunload, it is working sometimes but not consistent. Can anybody help me on this?

Dealt with this problem long back.

  • Sent a form request initially, failed to achieve. Worked 100/1 time.
  • Sent a AJAX request. Yup. Good for few times. Again the issue in hands.
  • Stopped trusting in browser request and implemented server side inactive methods.
  • If no request raised from client for x sec/minutes, closed his session (managed with sessiontimeout , cookies ).
  • That's 100% guaranteed and no browser dependencies.

Problems faced with browser trust.

  • God knows why sometimes it works.
  • Programmers cry when browser crash
  • No body knows when CPU shuts down and what happened to my
    browser close request
  • And many more natural disasters like this ....

You have to make the request a synchronous AJAX (pretty much the only circumstance in which synchronous AJAX is appropriately used); otherwise, it is a race whether the window will die before it manages to send a request or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM