IE block my cookie in iframe IE里Iframe的Cookie问题解决办法总结(转)

---恢复内容开始---php

There is a severe bug that a leader figured it out in a published project.html

In IE11, the page refreshs again and again, no contents are displayed.跨域

I followed this problem and recorded it below:安全

Because of the IE security privacy policy, the cookie in the 3-party can't be allowed in IE. So my cookie is blocked and can't be set successfully.cookie

I have found a wonderful blog that explanes the phenomeno and give the p3p privacy policy solution。dom

如下部份内容翻译自EricLaw [ex-MSFT]的《A Quick Look at P3P》

https://blogs.msdn.microsoft.com/ieinternals/2013/09/17/a-quick-look-at-p3p/ide

因为考虑有些网站经过iframe嵌套可能会跟踪你访问的站点,IE在对第三方cookie域会有网页隐私策略,因此限制和阻挡了cookie。post

第三方cookie的定义:页面中经过不一样的方式接收了不一样域的url。不一样方式例如:<script>, <img>, <link>, <frame>, <iframe>, <audio>, <video>以及包括设置了withCredentials标识的cross-domain XmlHttpRequest跨域请求。测试

在个人项目中涉及到子frame,示例:网站

IE9以前若是cookie被block了,会出现红眼睛进行提示,IE9(包括IE9)以后就不会出现红眼睛提示,而且console控制台也不报任何错误,能够经过 setting=》安全=》网页隐私策略进行查看:

 

 解决方案:

1.避免使用cookie存储

2.若是你避免不了,在3-party中HTTP的response header中设置P3P

如何设置?转载自宏宇转过来的文章(原谅我没找到原文的出处=.=)-- IE里Iframe的Cookie问题解决办法总结(转)

该文章有多重解决方案,我这里提取几种后台设置方案:

只须要设置 P3P HTTP Header,在隐含 iframe 里面跨域设置 cookie 就能够成功。他们所用的内容是:

P3P: CP='CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR'

ASP直接在头部加了头部申明,测试有效。
<%Response.AddHeader "P3P", "CP=CAO PSA OUR"%>

php的话,应该是以下写法:
header('P3P: CP=CAO PSA OUR');

ASP.NET的话
经过在代码上加Response.AddHeader("P3P", "CP=CAO PSA OUR")或者在Window服务中将ASP.NET State Service 启动。

JSP:
response.setHeader("P3P","CP=CAO PSA OUR")

 

关于P3P的了解,请查看官网https://www.w3.org/P3P/

相关文章
相关标签/搜索