.NET Cookie Parsing

  • Thread starter Thread starter Mike C#
  • Start date Start date
M

Mike C#

Is there a decent cookie parser out there somewhere? I keep running into
cookies that .NET can't handle. I've also found a couple of other parsers
but they're choking as well.
 
As I dig a little deeper into it, it appears that .NET is parsing the
Set-Cookie header properly. The cookies are even split up properly in the
private members deep down. But somehow they're getting *mangled* on their
way back up when you try to actually access them. This doesn't make a lot
of sense to me. Anyone had any experience with this? Hints, tips? Thanks.
 
I did some investigation, it turns out that the CookieCollection uses a
too-simple string split function instead of actually attempting to "parse"
the cookie. So any cookies that contain commas get mangled. I then tried
to grab the data from the Set-Cookie header, but those values get mangled in
a similar fashion. What's really annoying is that I can see the properly
parsed values in Visual Studio, way down in the private members of the
headers collection, but they're not exposed anywhere except in the Visual
Studio watch window. I ended up creating my own better parser to handle it.
The website I was playing around with was Expedia.com, BTW. I imagine there
are probably a lot of other websites that use commas in cookies - they
should fix the handling behaviour in .NET.
 
Mike C# wrote :

"I ended up creating my own better parser to handle it."

Hi Mike,

I imagine there are many people, besides myself, who would really appreciate
a brief tutorial and your solution if you have the time, inclination, and
freedom from contractual constraint, that would allow you to post an article
on CodeProject or a similar venue, or share code.

thanks, Bill
 
Bill Woodruff said:
Mike C# wrote :

"I ended up creating my own better parser to handle it."

Hi Mike,

I imagine there are many people, besides myself, who would really
appreciate
a brief tutorial and your solution if you have the time, inclination, and
freedom from contractual constraint, that would allow you to post an
article
on CodeProject or a similar venue, or share code.

This particular piece of code was part of a work for hire, so I can't post
it without permission. I'll discuss with the person I'm writing it for and
see if they're willing to allow it. If not, I may write another version of
the solution (time permitting) and post that. I really believe the absolute
best solution would be for the .NET team to fix the problem in the
Framework, but until then I guess we just have to make do with custom
parsing solutions :(
 
Back
Top