在 ASP.NET Web 中添加多个 Set-Cookie 标头 [英] Adding multiple Set-Cookie Headers in ASP.NET Web

查看:41
本文介绍了在 ASP.NET Web 中添加多个 Set-Cookie 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题.

当您向响应添加多个 Set-Cookie 标头时

When you add multiple Set-Cookie headers to the response

headers.Add("Set-Cookie", "a=b;Path=/;");
headers.Add("Set-Cookie", "c=d;Path=/;");

实际上它们是组合在一起的,并且只有一个标头与逗号分隔的 cookie 一起发送

actually they are combined and only one header is sent with comma-separated cookies

Set-Cookie: a=b;Path=/;,c=d;Path=/;

根据 RFC2109,这是一个有效的语法.但它不是根据 RFC6265,它弃用了 RFC2109

According to RFC2109 it is a valid syntax. But it is not according to RFC6265, which deprecates RFC2109

此外,最新的浏览器也不支持这种逗号分隔的语法.在 IE9Firefox 13Google Chrome 20 上进行了测试.

Moreover latest browsers does not support this comma-separated syntax as well. Tested on IE9, Firefox 13 and Google Chrome 20.

所有这些浏览器都只获取第一个 cookie.

All of these browsers took first cookie only.

请看下面的示例项目

https://github.com/mnaoumov/cookie-bug/

我想找到一些解决方法.

I want to find some workaround.

我希望有两个不同的 Set-Cookie 标头.

I expect to have two different Set-Cookie headers.

我尝试编写一些 MessageInspector 来重写 HTTP 标头.我找不到如何访问该标题.

I tried to write some MessageInspector to rewrite HTTP headers. I could not find how to access that headers.

有什么想法吗?

附言使用的技术:Web API

P.S. Used technology: Web API

推荐答案

根据 codeplex 上的回答 (http://aspnetwebstack.codeplex.com/workitem/288) 此问题是已知问题,与 WCF 自托管有关,应通过转移到 IIS 托管来解决.

According to answer on codeplex (http://aspnetwebstack.codeplex.com/workitem/288) this issue is known issue and related to WCF self-hosting and should be fixed by moving to IIS hosting.

这是 WCF 4 问题,标记为无法修复.

This is WCF 4 issue which marked as won't fix.

发现另一个具有相同结果的问题 WCF 4.0 Cookie 只有第一个被浏览器记录.

Found another question with the same outcome WCF 4.0 Cookie Only First is Recorded by Browser.

这篇关于在 ASP.NET Web 中添加多个 Set-Cookie 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆