Is there any way to know that user leaving a page with asp.net?

后端 未结 5 1942
遥遥无期
遥遥无期 2020-12-10 08:54

My question is a little bit tricky. at least I think. Maybe not, anyway. I want to know if there\'s any way to know if the user is leaving the page. Whatever if he clicks \"

5条回答
  •  旧时难觅i
    2020-12-10 09:37

    As mentioned, you can do it unreliably in JavaScript, but I am assuming from the wording of your question that you want to do it in the Server-side code ("the code-behind").

    That is impossible since the code-behind is running on a different computer (the web server) and has no idea what is going on at the user's computer unless the browser sends a request back to the server (which requires some Javascript or other client side code).

    If you must, use the session timeout events to clean up any state information you are storing beyond the lifetime of a request.

提交回复
热议问题