黎巴嫩的一位mvp寫的一篇文章

來源:互聯網
上載者:User

早上起來看到在google訂閱中看到aspalliance的一篇文章,立即饒有興趣地閱讀起來,題目的標題是:
Handle Browser Close Event on the Server-Side
意為在伺服器端捕獲瀏覽器關閉事件。這個技術是一個眾所周知的難題,我想看看他是怎麼解決的。結果看下去原來使用的body的onunload事件,觸發asp.net ajax 的pagemethod來釋放伺服器端的資源,很奇怪,這樣可以嗎?當重新整理postback,都回導致onunload事件的觸發,難道你都要釋放一次資源不成?結果在評論的第一條:
This article seemed promising, but unfortunately the javascript chain of events is going to cause undesired results.
第二條評論:
Unfortunately, the code in this article will not work. The onunload event fires every time you leave a page, so you'll be abandoning the session all the time.
接下來的幾條評論也都是關於這個does not work的問題,不過倒是有人給了幾個不起作用的原因:
1) The user has javascript disabled
2) The user's browser doesn't support javascript
3) The user kills the browser process
4) The user turns off their machine or has a power cut

也有人出了奇招:
One proposed solution is to use the mouse pointer to locate the window close button "X". Off course this will be purely based on the mouse movement but then you should also consider the chances of user resizing the window and then closing it. So, basically what is required is to get the mouse coordinates based on the openned browser window.

總之是不行啦,因為:The problem with onunload is that it will be fired even if you refresh the page or fire an ASP.NET postback event from any server side button.

不過有人提出的解決辦法是:
Another option for this case is that you use a keep alive functionality in your web application. after implementing keep alive, u can keep your session expire time to a short interval, say 1 or 2 mins. through this u can check for the session after every 1 or 2 mins and abandon it accordingly

不過真是汗一個:國外的mvp都寫這樣的沒有經過自己測試的文章,就發布到我覺得如同聖經般的網站上去嗎?比起院子裡的呂震宇和老趙等大俠,真是要汗一汗了....比起國外的開發人員,園子裡的小兄弟們算幸福的了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.