creating a cookie failing with safari, chrome, ie but working with FF

允我心安 提交于 2020-01-03 20:55:55

问题


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);
        }

回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/917475/creating-a-cookie-failing-with-safari-chrome-ie-but-working-with-ff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!