views:

450

answers:

3

Hi

I am having a strange problem with Internet Explorer not accepting my cookies. This is the cookie:

set-cookie: USUSERNAME=LrceSVu6mUJ9Ztmvp4oKSQ%3D%3D; version="1"; expires=Mon, 15-Jun-2009 11:42:21 GMT; path=/; domain=.us.is

It does not get stored for the domain dev-intranet.us.is or any other us.is domain. However setting the domain of the cookie to my dev machines ip address works perfectly:

set-cookie: USUSERNAME=LrceSVu6mUJ9Ztmvp4oKSQ%3D%3D; version="1"; expires=Mon, 15-Jun-2009 08:41:58 GMT; path=/; domain=192.168.34.104

Everything works as expecten in Firefox, Opera, Safari and Chrome but not IE7

Any ideas whats going on here?

Btw. using WebObjects WOCookie to create the cookie.

+3  A: 

The cookie in your example is for the "us.is" domain. IE ignores cookies set for two-letter domains. To be more exact, it seems to ignore cookies from domains with less than 5 characters (like yours: 2+2).

I remember this bug/feature from IE6 I believe, possibly earlier versions. Reading this, it looks like the behavior is still around in IE7.

An MSKB article suggesting an unpractical workaround can be found here: http://support.microsoft.com/kb/310676.

More practical is perhaps to get a longer domain name ;-) or to make sure users are always redirected to one canonical name, i.e. "www.us.is" and plant your cookies there.

conny
I assumed that there would be a question about IE and two-letter domains on S.O. already, but in that case I wasn't able to find it.
conny
Yes this is because of the IE bug .. very good :) And the workaround suggested by MS does not work. We solved this be setting Firefox as a default browser .. luckily our applications are for inhouse use :)
Atli Páll Hafsteinsson
A: 

Where could be the problem if domain is bigger then 2+2? Have a real problem with IE. Here is my test function on WebObjects :

    public WOActionResults giveMeACookie(){

  NSTimestamp oneMonthFromToday = new NSTimestamp();
  oneMonthFromToday = oneMonthFromToday.timestampByAddingGregorianUnits(1, 0, 0, 0, 0, 0);

  WOCookie cookie = new WOCookie("enjoyTheCookie", "yam yam!", null, "www.mydomain.com", oneMonthFromToday, false);

  session().context().response().addCookie(cookie);

  return this;
 }

BTW, I'm adressing my workstation by IP, not by domain. Also cookies are saved in all browsers e.g. Safari, Chrome, Firefox.

Alexei Voinovan
A: 

sorry for spamming, that is the real code that works for all browsers except IE :

public WOActionResults giveMeACookie(){

        NSTimestamp oneMonthFromToday = new NSTimestamp();
        oneMonthFromToday = oneMonthFromToday.timestampByAddingGregorianUnits(1, 0, 0, 0, 0, 0);

        WOCookie cookie = new WOCookie("enjoyTheCookie", "yam_yam!", "/", "", oneMonthFromToday, false);

        session().context().response().addCookie(cookie);

        return this;
    }

Already spent few hours finding the reason why it's not saving in IE. Thanks in advice.

-------------------------Update-----------------------

Solved the problem!

Here is the reason why IE was not accepting cookie : It seems to be that IE don't accept cookie if the domain name (4th WOCokie constructor param) is not defined or it differs from domain name of the page were the cookie comes from. So if you want to make your cookie tool work with ALL popular browsers - you better indicate domain name in it, and moreover, if there is any possibility that in future your web application will run on different domains - you must fetch this name dynamically from application context or whatever ...

Best regards guys, I hope that my experience will save few hours for you.