Logoff User when browser tab page is closed, ASP.NET MVC

后端 未结 5 476
攒了一身酷
攒了一身酷 2021-02-06 02:29

In one of the ASP.NET MVC apps we would like to logoff the user automatically if he closes the browser tab in which the app is opened.

We are using the following code wh

5条回答
  •  时光取名叫无心
    2021-02-06 02:51

    A browser clears all Session scoped objects only when it is completely closed, and not when an individual tab is closed.

    One way could be to use a very low Session timeout and have a server-side script poll every few seconds to hit an object on the page. This will extend Session time again. So if a tab is closed, the script can't find the object thereby allowing the Session to timeout. One problem here is if your app is on a pretty high load, your app could DoS itself!

提交回复
热议问题