Do I need to delete my cookie before re-adding it?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Ben Amada (ben_at_REpoMOweVErpick.com)
Date: 02/16/04


Date: Mon, 16 Feb 2004 05:08:31 -0700

Every time a user visits a particular page, I'm using the code below to add
a cookie that expires in 1 day.

My question is, a user may visit this page a few times within one day.
Before adding the cookie each time, do I need to delete the previous cookie?
Or will the new cookie just overwrite the old cookie? I'm trying to avoid
having multiple cookies on the user's machine -- just one. FYI, the cookie
"name" will be the same every time.

==========
Dim objCookie As HttpCookie
Dim ts As New TimeSpan(1, 0, 0, 0)
Dim dt As DateTime = DateTime.Now()

objCookie = New HttpCookie("cookie1", "value1")
objCookie.Expires = dt.Add(ts)
Response.Cookies.Add(objCookie)
==========

Thanks in advance,
Ben



Relevant Pages

  • Trouble with a simple cookie
    ... I have a page that will remember the user's settings using a cookie. ... Protected Sub Page_Load ... Dim objCookie As HttpCookie ... Dim strMyEvents As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Trouble with a simple cookie
    ... page to see the cookie (a bit strange compared to other folders, ... of the profile folders are not standard windows folders). ... Dim objCookie As HttpCookie ... Dim strMyEvents As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Trouble with a simple cookie
    ... The cookie should show up under the domain name you are hitting in your ... the profile folders are not standard windows folders). ... Dim objCookie As HttpCookie ... Dim strMyEvents As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Trouble with a simple cookie
    ... page to see the cookie (a bit strange compared to other folders, ... of the profile folders are not standard windows folders). ... Dim objCookie As HttpCookie ... Dim strMyEvents As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Do I need to delete my cookie before re-adding it?
    ... just check if cokie withname already exists on the client if EXISTS ... > Every time a user visits a particular page, I'm using the code below to add> a cookie that expires in 1 day. ... > Dim objCookie As HttpCookie ...
    (microsoft.public.dotnet.framework.aspnet)