views:

557

answers:

3

We are using the following code to create the security cookie. Everything works fine in Staging environment, however in the production environment the following code is unable to create a cookie in Safari, Chrome or IE but it does create a cookie successfully in Firefox. anything that you guys think i am missing or is wrong in here ?

public static void SetAuthenticationCookie(CustomIdentity identity)
     {
      ConfigSettings configSettings = ConfigHelper.GetConfigSettings();

      string cookieName = configSettings.CookieName;
      if (cookieName == null || cookieName.Trim() == String.Empty)
      {
       throw new Exception("CookieName entry not found in Web.config");
      }

      string cookieExpr = configSettings.CookieExpiration.ToString();

      string encryptedUserDetails = Encrypt(identity);

      HttpCookie userCookie = new HttpCookie(cookieName.ToUpper());
      if (cookieExpr != null && cookieExpr.Trim() != String.Empty)
      {
       userCookie.Expires = DateTime.Now.AddMinutes(int.Parse(cookieExpr));
      }
      userCookie.Values["UserDetails"] = encryptedUserDetails;
      userCookie.Values["Culture"] = configSettings.Customer.Culture;

      MyContext.Current.Response.Cookies.Add(userCookie);
     }
A: 

did you check whether you have Web Developer add-on and disabled cookies? or disabled cookies inside of FF?

動靜能量
Vikram
A: 

I've seen this issue related to the server having the incorrect UTC date/time. Firefox accepts regardless of the server date/time but other browsers won't set the cookie if the date/time is outside of a certain margin of error.

rickrobinett
+4  A: 

Safari and IE8 don't accept third-party cookies by default.

When you call out to another domain using JSONP, every cookie set by that script will be blocked by Safari and IE8. There is nothing you can do about that (in IE8, you could add a P3P policy, but that doesn't work in Safari).

There are workarounds for maintaining state across JSONP calls, but it's pretty complicated (you'll have to manage state manually and use document.cookie in the called javascript)

As an alternative, you can ask your users to lower the privacy settings in their browser, but this isn't something worth considering IMHO.

Philippe Leybaert
confirmed, also applies to latest versions of Opera as well.
Jeff Atwood
It looks like HTML5 `localStorage` (supported by most everything modern) is a decent workaround, see http://grack.com/blog/2010/01/06/3rd-party-cookies-dom-storage-and-privacy/ and http://diveintohtml5.org/storage.html
Jeff Atwood