English 中文(简体)
Splitting and recombining a large string in Cookies using ASP.NET
原标题:

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)

最佳回答

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 :)

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签