我正在创建一个模型,序列化并分配给cookie并将其传递给下一页。我能够在所有浏览器的下一页中获取cookie值,除了
- MAC -约希米特 - 野生动物园
-
IOS - 苹果手机 6 手机 - 野生动物园
我是否需要更新以下代码才能在 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"])) });
1st:您正在覆盖cookie - 而不是使用此代码使其过期。响应对象发送一次 - 与您的"新"cookie。如果 Cookie 存在 - 只需更改其值和/或内容。我会检查您在应用程序设置上的假设["cookiesecond"]
也试试这个:
If Request.ServerVariables("http_user_agent").IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) <> -1 Then
Me.Page.ClientTarget = "uplevel"
可能是浏览器上限不匹配...
中有一些逗号,并且在删除数据时会中断。
var cookieValue = (json).Replace(";", "").Replace(",", "***");
if (HttpContext.Current.Request.Browser.Type.ToLower().Contains("safari"))
{
HttpContext.Current.Response.AddHeader("Set-Cookie", sessionName + "=" + cookieValue + "; path=/;");
}
iOS safari 浏览器不允许使用 cookie。我们必须从 iOS 野生动物园浏览器启用 cookie 设置,
溶液:-- 我们实现了本地存储(java脚本概念(来克服iOS Safari浏览器中的cookie问题。