1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Expire Cookie

Discussion in 'C#' started by PartyRama.co.uk, Aug 20, 2009.

  1. #1
    Hi Gurus,

    How can i Expire an Cookie data

    As I am storing the customer Cart data in the Request.Cookie("")

    Once the order is complete, how do I clear the cart contents from the cookie?

    Regards
    Sri
     
    PartyRama.co.uk, Aug 20, 2009 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    You can't physically remove the cookie - but you can set the cookie's expire date :) I would say - instead of using cookies, use sessions (which just store a session id in a cookie, not data in the cookie) - then you can flush this data anytime you want and it doesn't matter if the cookie still exists - it just has your session id.
     
    ccoonen, Aug 20, 2009 IP
  3. WhiteOwl123

    WhiteOwl123 Greenhorn

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    You can set the expire date to a few hours ago so it will become expired.
     
    WhiteOwl123, Aug 20, 2009 IP
  4. zinist

    zinist Banned

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    43
    #4
    Using expires property you can remove the cookies
    example
    myCookie.Expires = DateTime.Now.AddDays(1);
     
    zinist, Jun 27, 2015 IP
  5. webcosmo

    webcosmo Notable Member

    Messages:
    5,840
    Likes Received:
    153
    Best Answers:
    2
    Trophy Points:
    255
    #5
    You can also set a new empty cookie with same name to the response.
     
    webcosmo, Aug 22, 2015 IP
  6. Jonathan Wood

    Jonathan Wood Member

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #6
    Be advised that, in some cases, expiring the cookie doesn't seem to work. This is because browsers like Chrome allow the browser to start up where it left off. And that means that any cookies that were active in the last session will still be active. This bit me a couple of times.
     
    Jonathan Wood, Nov 7, 2016 IP