开发者

IE 9 set cookie and redirect fails

In my spring-application I try to set a cookie and than redirect to a page where the cookie is read. The redirect to another webpage works, but setting the cookies fails only in IE9.

Cookie cookie = MyCookieHandler.createCookie(parameters, domain);
response.addCookie(cookie);

The redirect is handled buy setting the ModelAndView

modelView = new ModelAndView("redirect:" + getCallback());

As I said works fine in FF3+, Chrome an开发者_运维问答d IE7/IE8. What wrong in my app? Any suggestions?


I had similar issues with IE 8, 9, and 10 and the cache control headers did not help. After further research, I had to put a P3P privacy policy (from an older Java web app) in place and IE stored the cookie properly without the cache control headers.

This policy format is only honored by Internet Explorer these days, but provides the only reliable means of managing cookies without manual changes in the IE privacy settings. There are two parts to a P3P privacy policy: policy file and compact policy header. The compact policy header seems to work well enough. The different categories of P3P have compact codes for brevity in the header, e.g. navigation => NAV. At a minimum, I would start with INT, NAV, and UNI codes for the compact policy.

Here are two examples of how to pass back the header:

Grails/Java:
    response.setHeader("P3P", "CP='INT NAV UNI'");

PHP:
    header('P3P:CP="INT NAV UNI"')


After some tries I added the following:

response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache");

Now it works for me, don't know if this is the right solution and don't know why the caching is different in IE9 but now it works... thanks guys.


I had the problem of failed redirection before. It strangely seemed to work in Firefox, but failed in IE. The solution was to add a full URL to the redirect statement, i.e.

http://foo.com/new_site.html

instead of

new_site.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜