PDA

View Full Version : ASP Cookies


eRad
10-21-2004, 10:51 AM
simple task, strange problem.

i'm trying to use ASP cookies to replace ASP session objects. Wherever i created a session object, i put a Reponse.Cookies("cookiename")="cookievalue" (this was only done once, and it was indeed before the <html> tag)

then to refer to them i do Request.Cookies blah blah

anyway it seems to work just like a session - temporarily. once i close the browser it's lost. and if i look in my cookies folder i don't see any cookies created. What's going on? I tried this both on a localhost and on the server, both dont create cookies.

any ideas?

EDIT: Okay in firefox i can SEE the cookies. But when i close the browser, the one i created disappears. Only the ASPIDSTART one stays.... how do i make a 'permanent' cookie that doesn't go away on browser close?

jimmy_d
10-21-2004, 12:28 PM
Are you setting an expiration date?

eRad
10-21-2004, 01:06 PM
No.. lol. I was wondering about that..

Is there a way to specify a time period rather than a specific date?

EDIT: i guess i can just use the date() function, modded a bit

Thanks

jimmy_d
10-21-2004, 01:09 PM
Sure...

Response.Cookies("User_Info").Expires = Now() + 100
// it sets the expiration date 100 days from the current date

Borrowed from http://www.thecodeproject.com/asp/chocolatechipcookies.asp

eRad
10-21-2004, 01:14 PM
hehe i went through all the trouble of

Response.Cookies("usertype").Expires= DateAdd("d",7,now())

Eh :x

jimmy_d
10-21-2004, 01:16 PM
Live and learn...always a simpler way. :)

longcall911
11-01-2004, 11:00 PM
Then, if you want to remove the cookie even if the browser remains open (e.g., user logs out of your site):

Response.Cookies("User_Info").Expires = Now - 1