Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Cookies expire immediately, not when set to expire

Reply
Thread Tools

Cookies expire immediately, not when set to expire

 
 
Tongass Park Neighborhood Association, Juneau Alaska
Guest
Posts: n/a
 
      10-01-2009
I have tried the following:

To set the cookie

Response.Cookies("TongassParkPoll").Expires = Date + 30
Response.Cookies("TongassParkPoll")("1") = Cstr(Date)
response.write("<hr>" & Request.Cookies("TongassParkPoll")("1") &
"<hr>")

I upload the page and run it. The cookie returns the Date as set. I
then comment out the two Response.Cookies lines and it looks like:

'Response.Cookies("TongassParkPoll").Expires = Date + 30
'Response.Cookies("TongassParkPoll")("1") = Cstr(Date)

response.write("<hr>" & Request.Cookies("TongassParkPoll")("1") &
"<hr>")


I upload the page again and run it and get no value. The cookie
appears to only work in session state, it won't retain the cookie
based on the expiration date set.

I tried this test in IE8 and Mozilla 3.5.1. Both exhibit the same
issue. My IE security settings do not restrict cookies in any way
that I can find. Neither has Mozilla been set to restrict cookies.

If I try this test on my local IIS the cookie is retained.

Why is this not working and is there another way to make it work? I
want to setup an opinion poll using ASP and thought that the cookie
would be a good way to limit voting. If this method will not work
does anyone have a suggestion?
 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      10-01-2009
Tongass Park Neighborhood Association, Juneau Alaska wrote on 01 okt 2009
in microsoft.public.inetserver.asp.general:

> I have tried the following:
>
> To set the cookie
>
> Response.Cookies("TongassParkPoll").Expires = Date + 30
> Response.Cookies("TongassParkPoll")("1") = Cstr(Date)
> response.write("<hr>" & Request.Cookies("TongassParkPoll")("1") &
> "<hr>")
>
> I upload the page and run it. The cookie returns the Date as set. I
> then comment out the two Response.Cookies lines and it looks like:
>
> 'Response.Cookies("TongassParkPoll").Expires = Date + 30
> 'Response.Cookies("TongassParkPoll")("1") = Cstr(Date)
>
> response.write("<hr>" & Request.Cookies("TongassParkPoll")("1") &
> "<hr>")
>
>
> I upload the page again and run it and get no value. The cookie
> appears to only work in session state, it won't retain the cookie
> based on the expiration date set.
>
> I tried this test in IE8 and Mozilla 3.5.1. Both exhibit the same
> issue. My IE security settings do not restrict cookies in any way
> that I can find. Neither has Mozilla been set to restrict cookies.
>
> If I try this test on my local IIS the cookie is retained.
>
> Why is this not working and is there another way to make it work? I
> want to setup an opinion poll using ASP and thought that the cookie
> would be a good way to limit voting. If this method will not work
> does anyone have a suggestion?


As usual you should try to debug, that we cannot do for you.

Are both serverside and clientside GMT-clock correctly set?

Did you try Now() in stead of Date() ?

What if you set the expiring to Now() + 5000 ?

BTW, why the () in

> response.write("<hr>" & Request.Cookies("TongassParkPoll")("1") &
> "<hr>")


response.write "<hr>" & Request.Cookies("TongassParkPoll")("1")

will do fine.



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
SQLDude
Guest
Posts: n/a
 
      11-24-2009
Here is a little Stupid Cookie Trick which can be very helpful if you
want to READ the Expiration Date of a Cookie:

(And you thought there was no way to Read a Cookie Expiration Date,
too, right?

Just make all your cookies have a Cookie Keys collection like this:

Response.Cookies("5000Watches") = Request.Servervariables
("REMOTE_ADDR")
Response.Cookies("5000Watches").expires = Now() + 1
Response.Cookies("5000Watches").domain = "5000Watches.com"
Response.Cookies("5000Watches")("Expiration") = Now() + 1
Response.Cookies("5000Watches")("IPAddress") =
Request.Servervariables("REMOTE_ADDR")
Response.Cookies("5000Watches")("UserAgent") =
Request.Servervariables("USER_AGENT")

.... then you can READ this parallel universe Expiration Date by doing
this....

Response.Write Request.Cookies("5000Watches")("Expiration") OR

dtExpireDate = Request.Cookies("5000Watches")("Expiration")

And all along everyone has been telling me that there is NO WAY to
Read a Cookie's Expiration Date....
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who ASP .Net 7 09-18-2008 07:49 PM
Cookies will not expire (noob question) th3dude ASP .Net 4 07-24-2008 09:03 PM
set cookies to expire Gonzosez ASP General 2 01-10-2006 10:01 PM
is it possible to know when cookies expire ? Mel HTML 3 03-16-2005 06:31 PM
Forms Authentication Cookies Never Expire Joey Powell ASP .Net 2 12-04-2003 08:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57