Cookie does not work in MAC-Safari and iOS Mobile-Safari

I create a model by serializing and assigning to a cookie and passing it to the next page. I can get cookies on the next page in all browsers except

  • MAC-Yoshemite - Safari
  • IOS - IPHONE 6 Mobile Safari

    Do I need to update the code below to work in Safari.

    string CookieName= "dsResponse";
    string json = new JavaScriptSerializer().Serialize(model);    
    
    if (HttpContext.Current.Request.Cookies[CookieName] != null)
    {
        HttpContext.Current.Response.Cookies[CookieName].Expires = DateTime.Now.AddDays(-1);
    }
    HttpContext.Current.Response.SetCookie(new HttpCookie(CookieName)
    {
        Value = json,
        HttpOnly = false,
        Expires = DateTime.Now.AddSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["cookiesecond"]))
    });
    
+4
source share
3 answers

1st: you rewrite the cookie - not ending with this code. The response object is sent once - with your "new" cookie. If a cookie exists, simply change its value and / or content. I would check your assumption on AppSettings ["cookiesecond"]

Also try the following:

If Request.ServerVariables("http_user_agent").IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) <> -1 Then
    Me.Page.ClientTarget = "uplevel"

, ...

0

JSON .

var cookieValue = (json).Replace(";", "").Replace(",", "***");
 if (HttpContext.Current.Request.Browser.Type.ToLower().Contains("safari"))
            {
                HttpContext.Current.Response.AddHeader("Set-Cookie", sessionName + "=" + cookieValue + "; path=/;");
            }
0

By default, cookies are not allowed for the Safari iOS browser. We must enable cookie settings from the Safari iOS browser,

Solution: - - we implemented local storage (the concept of java script) to overcome the problems with cookies in the Safari iOS browser.

0
source

Source: https://habr.com/ru/post/1674325/


All Articles