IE block my cookie in iframe

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

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

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.

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

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

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

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

第三方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/

原文地址:https://www.cnblogs.com/echo2016/p/8371678.html