ASP.NET不能正确处理逗号分隔的饼干逗号、饼干、正确处理、ASP

2023-09-03 17:26:21 作者:心已死

根据的RFC ,个别饼干在曲奇HTTP标头可能是用逗号以及用分号分隔。但是,ASP.NET不正确地分析逗号情况 - 它不算逗号作为分隔符,但认为该值只是其中的一部分

According to the RFC, individual cookies in the "Cookie" HTTP header may be separated by commas as well as by semicolons. However, ASP.NET does not parse the commas case correctly - it does not count comma as a separator, but considers it just part of the value.

例如 如果客户端发送标题的Cookie:A = B,C = D ,则ASP.NET应用程序将看到的只是一个名为cookie的一与价值的B,C = D。

For example If a client sends header Cookie: a=b, c=d, then the ASP.NET application will see just one cookie named "a" with value "b, c=d".

作为一个特殊的情况下,当客户端发送一些饼干头(每个饼干)同样的事情发生,而不是将所有的Cookie在一个头。从HTTP的角度看,这是完全有效的,并在这样的情况下,报头的有效值应该是它的所有实例由逗号分隔的值的级联

As a special case, the same thing happens when the client sends several Cookie headers (one for each cookie) instead of combining all cookies in one header. From HTTP perspective, this is completely valid, and in such case the effective value of the header should be concatenation of the values of all its instances separated by commas.

是否有人知道一个解决方法(或者一个修复?)这个?我绝对需要得到这个工作,因为我不控制客户端。

Does anybody know a workaround (or maybe a fix?) for this? I absolutely need to get this working, because I don't control the client.

P.S。具有讽刺意味的​​是,根据this螺纹时,在.NET内置的HTTP客户端的(又名HttpWebRequest的)行为是正好相反,并且还引起的问题。 : - )

P.S. It is ironic that, according to this thread, the .NET built-in HTTP client's (aka HttpWebRequest) behavior is just the opposite, and also causes problems. :-)

推荐答案

我相信最简单的解决方案,以获得所需的(标准正确性不管)的行为将是创建一个HTTP模块,将正确地从HttpContext.Request分析该信息, .Headers及地点改正信息HttpContext.Request.Cookies。

I believe the simplest solution to getting the behavior desired (regardless of standards correctness) would be to create an HttpModule that would correctly parse this information from the HttpContext.Request.Headers and place corrected information in HttpContext.Request.Cookies.