tags:

views:

186

answers:

1

We're using a cookie for some non-sensitive convenience data about our site visitors. We emit three values: 1) creation date (in ticks), 2) user data, JSON serialized, 3) validation hash

We're seeing a fair number of requests coming in with only half a cookie. They contain the full date and truncated user data, something like {"Foo":false,"Bar":0

This is a high-volume site, and the number of bad cookies looks to be about 1-3 per minute (out of 8-10 thousand page requests per minute).

Anyone experience anything similar? I'm wondering if we have a browser that doesn't like the JSON, or maybe the header is getting truncated by some browsers, or maybe there's a JSON serializer bug. We're using the JavaScriptSerializer in .NET 3.5.

+1  A: 

unencoded embedded commas and over stuffed cookies are the typical causes of this behavior

Sky Sanders
Makes good sense - JSON generates commas, and we are not currently encoding the result. I am going to look at encoding the JSON data and get back to you.
Stuart
Added url encoding - won't know for sure until the change makes it to production and experiences our normal load, but the header certainly looks "righter".
Stuart
@stuart - yeah, seems pretty obvious to me. also, you need to be really really aware of how big your cookies are and how many cookies you have because cookie overflow is a silent killer. lol...
Sky Sanders
I didn't encode the entire cookie, and saw an interesting side effect as a result: http://stackoverflow.com/questions/2342253/do-some-browsers-encode-cookies
Stuart