What would be the best method for serializing a Dictionary for use in a single Cookie?
There are examples of XML-serializable dictionaries out there which would work fine for very small dictionary objects. However, since size is a concern with cookies, I'd recommend exploring something a little less flexible but more compact.
Have you also considered storing the data on the server and just storing a key to the data in the cookie?
I don't think Dictionary is marked [Serializable]. If the key and values are primitive types (int, string, etc) you could use a comma/semicolon delimited list:
key1,value1;key2,value2;key3,value3
If you have complex types in your keys/values, I would recommend against serialization. Don't want to deal with 50K cookies, you never know how it will work from browser to browser.
I don't recommend it, the performance of serializing/deserializing a cookie on every request is terrible.
Figure out a way to represent the structure yourself to/from a string.
If you absolutely must serialize it:
http://petesbloggerama.blogspot.com/2006/07/binary-serialization-to-from-string.html