Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Simple question about cookies

Reply
Thread Tools

Simple question about cookies

 
 
=?Utf-8?B?Sm9l?=
Guest
Posts: n/a
 
      08-04-2005
Hi,

I’m creating a cookie named “tick” that should expire after 1 day when user
logs in.

TheDomain = ".www.test.com"
ThePath = "/dir1/subdir"
Response.Cookies("tick")("ID") = Session("userEmail")
Response.Cookies("tick").Expires = DateAdd("d", 1, Now())
Response.Cookies("tick").Domain = TheDomain
Response.Cookies("tick").Path = ThePath

I want to have a logout link. When clicked, I am trying to set the expiry
date of cookie to say 5 days back like this to tell browser that this cookie
has expired and it should remove it.

Response.Cookies("tick").Expires = DateAdd("d", -5, Now())

But I noticed that I am not able to change the cookie’s expiry date by above
line. Can someone tell me what mistake I’m making?

Thanks,

Joe

 
Reply With Quote
 
 
 
 
Tom.PesterDELETETHISSS@pandora.be
Guest
Posts: n/a
 
      08-04-2005

I tested your code and it does what is exepcted. Once the server sends a
cookie with the expire date in the past it wont send the cookie to the server
the next time.

Don't forget that when the browser requests the logout page it will still
send the cookie. The logout page sends the command to forget the cookie and
_only then_ the browser wont send it next time.

Is that what's confusing you?

Let me know if you have any more questions..

Cheers,
Tom Pester

> Hi,
>
> I'm creating a cookie named "tick" that should expire after 1 day when
> user logs in.
>
> TheDomain = ".www.test.com"
> ThePath = "/dir1/subdir"
> Response.Cookies("tick")("ID") = Session("userEmail")
> Response.Cookies("tick").Expires = DateAdd("d", 1, Now())
> Response.Cookies("tick").Domain = TheDomain
> Response.Cookies("tick").Path = ThePath
> I want to have a logout link. When clicked, I am trying to set the
> expiry date of cookie to say 5 days back like this to tell browser
> that this cookie has expired and it should remove it.
>
> Response.Cookies("tick").Expires = DateAdd("d", -5, Now())
>
> But I noticed that I am not able to change the cookie's expiry date by
> above line. Can someone tell me what mistake I'm making?
>
> Thanks,
>
> Joe
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9l?=
Guest
Posts: n/a
 
      08-05-2005
Yes I am confused. When the clicks on log out link, I set the expiry to past
date. But when I click on one of secured pages (pages that check "tick"
cookie before displaying the page) they allow me to see the page whcih
shouldn't happen because cookie is expired. In short my logout is not
working out.

Joe


"" wrote:

>
> I tested your code and it does what is exepcted. Once the server sends a
> cookie with the expire date in the past it wont send the cookie to the server
> the next time.
>
> Don't forget that when the browser requests the logout page it will still
> send the cookie. The logout page sends the command to forget the cookie and
> _only then_ the browser wont send it next time.
>
> Is that what's confusing you?
>
> Let me know if you have any more questions..
>
> Cheers,
> Tom Pester
>
> > Hi,
> >
> > I'm creating a cookie named "tick" that should expire after 1 day when
> > user logs in.
> >
> > TheDomain = ".www.test.com"
> > ThePath = "/dir1/subdir"
> > Response.Cookies("tick")("ID") = Session("userEmail")
> > Response.Cookies("tick").Expires = DateAdd("d", 1, Now())
> > Response.Cookies("tick").Domain = TheDomain
> > Response.Cookies("tick").Path = ThePath
> > I want to have a logout link. When clicked, I am trying to set the
> > expiry date of cookie to say 5 days back like this to tell browser
> > that this cookie has expired and it should remove it.
> >
> > Response.Cookies("tick").Expires = DateAdd("d", -5, Now())
> >
> > But I noticed that I am not able to change the cookie's expiry date by
> > above line. Can someone tell me what mistake I'm making?
> >
> > Thanks,
> >
> > Joe
> >

>
>
>

 
Reply With Quote
 
Tom.PesterDELETETHISSS@pandora.be
Guest
Posts: n/a
 
      08-05-2005


- Can you access those pages without a cookie. You can test this by deleting
all cookies in ie and typing the url to a cookie protected page.
- I tested your code (Response.Cookies("tick").Expires = DateAdd("d", -5,
Now())) and it realy does delete the cookie.
You can check this for yourself with this tool : http://www.blunck.info/iehttpheaders.html

This tool will ultimatly diagonse the problem but you have to understand
a little about the http protocol. If some caching is involved this tool will
also show you this.

If it doesn't work out send my some code and I'll find the error.


Let me know if you have any more questions..

Cheers,
Tom Pester

> Yes I am confused. When the clicks on log out link, I set the expiry
> to past date. But when I click on one of secured pages (pages that
> check "tick" cookie before displaying the page) they allow me to see
> the page whcih shouldn't happen because cookie is expired. In short
> my logout is not working out.
>
> Joe
>
> "" wrote:
>
>> I tested your code and it does what is exepcted. Once the server
>> sends a cookie with the expire date in the past it wont send the
>> cookie to the server the next time.
>>
>> Don't forget that when the browser requests the logout page it will
>> still send the cookie. The logout page sends the command to forget
>> the cookie and _only then_ the browser wont send it next time.
>>
>> Is that what's confusing you?
>>
>> Let me know if you have any more questions..
>>
>> Cheers,
>> Tom Pester
>>> Hi,
>>>
>>> I'm creating a cookie named "tick" that should expire after 1 day
>>> when user logs in.
>>>
>>> TheDomain = ".www.test.com"
>>> ThePath = "/dir1/subdir"
>>> Response.Cookies("tick")("ID") = Session("userEmail")
>>> Response.Cookies("tick").Expires = DateAdd("d", 1, Now())
>>> Response.Cookies("tick").Domain = TheDomain
>>> Response.Cookies("tick").Path = ThePath
>>> I want to have a logout link. When clicked, I am trying to set the
>>> expiry date of cookie to say 5 days back like this to tell browser
>>> that this cookie has expired and it should remove it.
>>> Response.Cookies("tick").Expires = DateAdd("d", -5, Now())
>>>
>>> But I noticed that I am not able to change the cookie's expiry date
>>> by above line. Can someone tell me what mistake I'm making?
>>>
>>> Thanks,
>>>
>>> Joe
>>>



 
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
What's the proper way of reading cookies? Request.Cookies("mycook") doesnt work user ASP .Net 3 03-31-2007 01:53 PM
Response.Cookies vs Request.Cookies Alex Nitulescu ASP .Net 1 02-03-2005 09:43 AM
Persistent Cookies vs. session cookies Andy Fish Java 3 11-06-2003 10:44 AM
Good Cookies bad Cookies? AK Computer Support 23 10-26-2003 05:20 AM



Advertisments