Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

ASP Cookie Question

6:40 pm on Aug 16, 2007 (gmt 0)

New User

10+ Year Member

joined:May 29, 2007
votes: 0

I am building a site that allows users to rate images. I want a cookie created once they rated the image and from then on the page would show the results and not the scale unless of course they deleted their cookies... all pretty standard stuff.

My question is instead of creating a cookie for every image can I use a variable in the cookies.

I know this does not work but if there is something like this available it would be very helpful to me.

For Example: response.cookies("sitename")(ImageVariable) = 1


3:50 am on Aug 17, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 28, 2002
votes: 0

Yes, you can have subkeys for a cookie.

Response.Cookies("site1")("image1") = " ../image1.jpg"
Response.Cookies("site1")("image2") = " ../image2.jpg"

... so you should be able to do this:

sSubKeyname = "image1"
Response.Cookies("site1")(sSubKeyname) = " ../image1.jpg"

<do more stuff>

sSubKeyname = "image2"
Response.Cookies("site1")(sSubKeyname) = "../image2.jpg"

warning, I haven't tried this code, but it should work

This leaves a single cookie named site1. Not too many subkeys....There are limits as to how much you can stuff in a cookie, plus it can slow the roundtrip time for the user. With each click they are generating more 'weight' in the Request.

Can the session state store any of this or are you looking to persist the data beyond a single session?

3:52 am on Aug 17, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 13, 2005
votes: 0

The best way to do it, is to set some sort of unique identifier in the cookie, like a GUID or something. Then request that GUID whenever the user rates an image and store that GUID in the DB next to their rating. When the user pulls up an image, it would check to see if that GUID already existed in the DB for that image and show the image sans scale.

You only have 4KB of cookie space to work with, so if a user goes and rates a whole bunch of photos, you could run against that size limit if you're storing each photoId or whatever.


1:56 pm on Aug 17, 2007 (gmt 0)

New User

10+ Year Member

joined:May 29, 2007
votes: 0

Cool. I will try the subkey to see how it works but it sounds like the guid is the way I need to go… thanks for your help.