开发者

Best way to handle Cookies and arrays?

I want to save basket of liked properties for visitors. The information I need to save is ID, name, URL, and possiby image URL.

What is the best way to do that with cookies? I dont want to have any login/registration screens. I just want give visitor opportunity to click save to basket and put this into cookies for later visits.

Is client s开发者_C百科ide cookie enough for this?


I think that the best thing to do is storing a list of productId within the cookie. You are in charge to find the name, URL and image from the ID when you display the basket. Not the cookie. (Imagine you change the image directory?) Also one cookie should be enough. Do not make one by product!

You don't have to use login screens with cookie, it's basically just a storage. Did you looked at MSDN on HttpCookies for C#?

The drawback of cookies are:

  1. The client may not accept the cookie
  2. The client may clear the cookie

But I think this is not problematic for basket management.


If your information is small - putting it into cookies is fine (like list of product IDs). If you plan to put significant amount of data (about 3K+ into single cookie or 20K+ split between cookies) you should consider other ways to store information - ASP.Net SessionState is one possible option.

There are restrictions on length of individual cookie, total cookies size for given domain and total cookie size. Browsers are free to drop some or all cookies when this limits are hit. To work around restriction on single cookie lenght you can split value between several cookies.

Depending on data you plan to store in the cookie you may need to %-encode values or Base64 encode (for binary data).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜