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

查看:538
本文介绍了在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

此外,最新的浏览器也不支持此逗号分隔的语法.在 IE9 Firefox 13 Google 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.

有什么想法吗?

P.S.二手技术: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天全站免登陆