简体   繁体   English

浏览器关闭时调用页面方法

[英]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. 当用户关闭特定ASP.NET 4.5.1网站的浏览器或活动选项卡时,我需要调用pagemethod,尝试onbeforeunload,它有时工作但不一致。 Can anybody help me on this? 有人可以帮我这个吗?

Dealt with this problem long back. 长期处理这个问题。

  • Sent a form request initially, failed to achieve. 最初发送表单请求,未能实现。 Worked 100/1 time. 工作时间为100/1。
  • Sent a AJAX request. 发送了一个AJAX请求。 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 ). 如果客户端没有提出x秒/分钟的请求,则关闭其会话(使用sessiontimeoutcookies管理)。
  • That's 100% guaranteed and no browser dependencies. 这是100%保证,没有浏览器依赖。

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 没有人知道CPU什么时候关闭以及我的情况发生了什么
    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); 您必须使请求成为同步AJAX(几乎是唯一适用于同步AJAX的情况); otherwise, it is a race whether the window will die before it manages to send a request or not. 否则,在设法发送请求之前窗口是否会死亡是一场竞赛。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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