简体   繁体   中英

Session Cookie has wrong behaviour in IE11?

please check the following two images:

IE11中的Cookies

铬的饼干

The logic I want to achieve is the following: We have a web portal in which a user can simulate another user. Now when the user ends his session and starts the browser again, the simulation should be stopped and the user logged out.

To achieve that I set two cookies on login, one cookie with an expiry date of +99 days and another cookie without the expires attribute.

In IE11 the expires column is completely empty, I don't know why. But still when I close the window and end the session, the cookie is still present and my logic doesn't work.

checkSimulationCookieAndLogOut() {
    // Checks for cookie if a user is simulated and logs out
    let self = this;
    let sessionCookie = self.globalFunctions.getCookie('user-is-simulated-session-cookie');
    let userSimulationCookie = self.globalFunctions.getCookie('user-is-simulated');
    if(!sessionCookie && userSimulationCookie) {
        //self.globalFunctions.automaticLogoutAndRedirect();
        self.globalFunctions.deleteCookie('user-is-simulated');
        console.log('test');
    }
}

The cookies are set like this:

setCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}

self.globalFunctions.setCookie('user-is-simulated-session-cookie', 'true');
self.globalFunctions.setCookie('user-is-simulated', 'true', 99);

The self.globalfunctions is just a class holding some functions which are shared throughout the application.

Does anyone know what I can do differently or where I'm doing something wrong?

Okay I found out that it worked on a windows machine with IE11. So maybe it has something to do with virtualbox.

But generally it worked.

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