gpt4 book ai didi

c# - .NET CookieException "Cookie format error"当线程区域性不是英语时 - 仅在某些环境中

转载 作者:太空宇宙 更新时间:2023-11-03 11:07:28 26 4
gpt4 key购买 nike

我正在尝试在调用其他 Web 服务的 ASP.NET 应用程序中进行一些 cookie 管理。我遇到了一个错误,我只能在某些环境中重现。我的问题是:

  1. 生产和开发之间的差异是否足以导致此问题?
  2. 我如何弄清楚生产/开发之间的区别?
  3. 我该怎么做才能解决这个问题?

以下是我用来重现问题的详细信息。我看到的错误是:

Unhandled Exception: System.Net.CookieException: 
An error occurred when parsing the Cookie header for Uri 'http://example.com/'.
---> System.Net.CookieException: <b>Cookie format error.</b>
at System.Net.CookieContainer.CookieCutter(Uri uri, String headerName,
String setCookieHeader, Boolean isThrow)
--- End of inner exception stack trace ---
at System.Net.CookieContainer.CookieCutter(Uri uri, String headerName,
String setCookieHeader, Boolean isThrow)
at System.Net.CookieContainer.SetCookies(Uri uri, String cookieHeader)
at Program.Main() in c:\Sample\Program.cs:line 21

我创建了一个重现问题的控制台应用程序(下面的相关部分)。完整代码位于 https://compilr.com/adutton/cookiecutterexample/main.cs

string[] cultures = new[] { "en-US", "es-MX" };
const string cookieHeader = ".ASPXAUTH=SECURITYINFO; domain=.example.com; "
+ "expires=Mon, 06-Mar-2023 18:36:33 GMT; path=/; HttpOnly";

foreach (string culture in cultures)
{
Console.WriteLine("CookieCutting with culture: " + culture);
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);

CookieContainer ctr = new CookieContainer();
// The following line throws an exception
ctr.SetCookies(new Uri("http://example.com/"), cookieHeader);
}

此代码适用于我的开发机器(Windows 7、x64、.NET 4.5.50709),但不适用于生产环境(Windows Server 2008 R2 Enterprise、x64、.NET 4.0.30319),其中代码为 es-MX 文化抛出异常。

如果我从 cookie header 中删除日期,异常就会消失,这让我相信这是 cookie 解析器的本地化问题。也许这已在 .NET 4.0 -> 4.5 中修复?

最佳答案

我认为问题在于星期几之后的逗号,如下所示:Help With .NET CookieContainer

关于c# - .NET CookieException "Cookie format error"当线程区域性不是英语时 - 仅在某些环境中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15257004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com