简体   繁体   中英

Sending commands from server side (.NET) to browser

We have some web application that allows users login and do some work. 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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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