homepage Welcome to WebmasterWorld Guest from 67.202.56.112
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Visit PubCon.com
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
ASP Cookie Question
UFfan




msg:3424061
 6:40 pm on Aug 16, 2007 (gmt 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

Thanks

 

duckhunter




msg:3424378
 3:50 am on Aug 17, 2007 (gmt 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?

carguy84




msg:3424380
 3:52 am on Aug 17, 2007 (gmt 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.

Chip-

UFfan




msg:3424677
 1:56 pm on Aug 17, 2007 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved