[thelist] removing cookies in ASP

Anthony Baratta Anthony at Baratta.com
Thu Apr 29 16:42:27 CDT 2004

At 12:42 PM 4/29/2004, Andrew wrote:
>Hey everyone, I have a question about removing cookies in ASP.  I'm building
>a shopping cart system and currently if I want to remove a cookie, I just
>set it to '0'.  Is there a better way to do this?
>Can I expire only one cookie in a set?
>For example, if I want to keep this one:
>and delete this one:
>I do this:
>removeItem = Request("removeitem")
>For each item in Response.Cookies("cart")
>     If Request.Cookies("cart")(item) = removeItem Then
>         Response.Cookies("cart")(item) = 0
>     End If


First off, you should use th Session Object or a DB backend to store your 
Cart Information. Storing this data in the cookie itself is not a very 
clean solution.

Second, to expire a cookie you use the .Expires property. All you are doing 
with your solution is setting the cookie item to "zero". This might make 
your application ignore that item - but it's not "removing" the cookie.


You can expire each item separately, if you really need to:

         Response.Cookies(cookie)(key).Expires = #Date#

Anthony Baratta
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."

More information about the thelist mailing list