Simple question about cookies

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9l?=, Aug 4, 2005.

  1. 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
     
    =?Utf-8?B?Sm9l?=, Aug 4, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Sm9l?=

    Guest

    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
    >
     
    , Aug 5, 2005
    #2
    1. Advertising

  3. 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
    > >

    >
    >
    >
     
    =?Utf-8?B?Sm9l?=, Aug 5, 2005
    #3
  4. =?Utf-8?B?Sm9l?=

    Guest

    - 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
    >>>
     
    , Aug 5, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,631
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,612
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    697
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    538
  5. _Who
    Replies:
    7
    Views:
    2,777
Loading...

Share This Page