Question

I have a large string that I want to save in a cookie, however I don't know what the best practices are for max string length per cookie, and max cookie count.

What logic should I use to split the string and later combine a set of cookies?

(Microsoft ADFS and perhaps Siteminder do this technique so I would be interested in what thier implementation is)

Was it helpful?

Solution

Cookies is something that handle by browsers, so each browser have different limits.

Split the cookie can help only temporary because there is also a limit to the total cookies data for each site, but also you add an overhead on the data transfer on each page

The limits for each browser per cookie:
Internet Explorer handle max cookie of about 3904 bytes
Mozilla Firefox handle max cookie of about 3136 bytes

When I make some tests on Chrome, the chrome crash inside with a large cookie, and no message appear nether the page.

Now both Netscape and Microsoft have measures in place that limit the number of cookies base on RFC 2109 limitations of total cookies count to 300 ref: http://www.cookiecentral.com/faq/#2.5
This is done for many reasons, one of them is the hacking, imaging a site that go and upload a full video on the cookies :) and full up your hard disk with it...

I say that the best practices is to keep a small cookie reference on the browser, and connect it with the real data on the server. The smaller the better from all aspects.

How to make your tests for the cookie, you can make a code like that.

if(Request.Cookies["cookieTest"] == null)
    Request.Cookies["cookieTest"].Value = "more text into cookie";
else
    Request.Cookies["cookieTest"].Value += "more text into cookie";

// check now the size
Responce.Write(Request.Cookies["cookieTest"].Value.Length);

My experience show many random unpredicted problems when you try to use uncontrolled large data on cookies. I have hear many times support say: Clear your cookies and try again :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top