简体   繁体   English

从服务器端(.NET)向浏览器发送命令

[英]Sending commands from server side (.NET) to browser

We have some web application that allows users login and do some work. 我们有一些Web应用程序,允许用户登录并执行一些工作。 But sometimes users work with our web site opening more then one browser and this causes us a lot of problems. 但是有时候用户使用我们的网站打开的浏览器不止一个,这给我们带来了很多问题。 How could we implement the following - on user log in to our web site, make automatic log out in all his previously logged in browsers? 我们如何实现以下功能-在用户登录到我们的网站时,在其以前登录的所有浏览器中自动注销?

Thanks a lot. 非常感谢。

You can use JS localStorage on page load to detect a user login, the event will be fired on every tabs or window opened within the same domain : 您可以在页面加载时使用JS localStorage来检测用户登录,该事件将在同一域内打开的每个标签或窗口上触发:

function storageChange(event) {
    if(event.key == 'user_login') {

        // logout - except current window
    }
}
window.addEventListener('storage', storageChange, false);

//when user logs in
window.localStorage.setItem('user_login', true);

That will work only if the user is using the same browser multiple times. 仅当用户多次使用同一浏览器时,此方法才有效。

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

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