Sending browser cookies during a 302 redirect

2019-01-13 14:40发布

Are there any issues with sending back a cookie during a 302 redirect? For example, if I create a return-to-url cookie and redirect the user in the same response will any (modern) browser ignore the cookie?

5条回答
甜甜的少女心
2楼-- · 2019-01-13 14:56

One notice (to save developer's life):

IE and Edge are ignoring Set-Cookie in redirect response when domain of the cookie is localhost.

Solution:

Use 127.0.0.1 instead of localhost.

查看更多
Summer. ? 凉城
3楼-- · 2019-01-13 14:57

In my case I set CookieOptions.Secure=true, but tested it on http://localhost., and browser hide cookies according to the setting.

To avoid such problem, you can make cookie Secure option to match protocol Request.IsHttps,e.g.

new CookieOptions()
                {
                    Path = "/",
                    HttpOnly = true,
                    Secure = Request.IsHttps,
                    Expires = expires
                }
查看更多
萌系小妹纸
4楼-- · 2019-01-13 14:59

Here is the Chromium bug for this issue (Set-cookie ignored for HTTP response with status 302).

查看更多
Explosion°爆炸
5楼-- · 2019-01-13 15:03

Most browser are accepting cookies on 302 redirects. I was quite sure of that, but I made a little search. Not all modern browsers. Internet archive Link from a now removed/dead/ microsoft connect Q/A on Silverlight Client HTTP Stack ignores Set-Cookie on 302 Redirect Responses (2010)

I think we now have a replacement for IE6 and it's Windows Mobile browsers...

查看更多
smile是对你的礼貌
6楼-- · 2019-01-13 15:10

According to this blog post: http://blog.dubbelboer.com/2012/11/25/302-cookie.html all major browsers, IE (6, 7, 8, 9, 10), FF (17), Safari (6.0.2), Opera (12.11) both on Windows and Mac, set cookies on redirects. This is true for both 301 and 302 redirects.

查看更多
登录 后发表回答