11

please check the following two images:

Cookies in IE11

Cookies in chrome

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?

Frederik Witte
  • 1,167
  • 2
  • 11
  • 35
  • maybe something like this is the cause? https://stackoverflow.com/questions/22690114/internet-explorer-11-wont-set-cookies-on-a-site – TerranGaming Jul 26 '18 at 11:34
  • Hey, thank you I saw that as well, but I don't set the "domain" value – Frederik Witte Jul 26 '18 at 11:42
  • Try setting the domain value to '/' (root) everywhere. I had a similar issue a short while ago and that solved it. Also may I ask why you don't use sessions instead of cookies for this? Sounds more appropriate for that kinda task to me. – confetti Jul 30 '18 at 23:35
  • how did you end the session? Just by closing the browser? are you sure ie11 is ending the sessions on browser close and not restarting the session on open? Or are you detecting the window close in your code and invalidating the session then? – Emil Aug 01 '18 at 14:30
  • Could this be the issue? https://stackoverflow.com/questions/16416241/set-cookie-expire-property-clock-skew-and-internet-explorer-issue IE has a reputation for not showing what it should – Nathan Stockton Aug 05 '18 at 09:37

1 Answers1

0

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.

Frederik Witte
  • 1,167
  • 2
  • 11
  • 35