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

B

Ben Amada

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
 
N

.NET Follower

hi,
just check if cokie withname already exists on the client if EXISTS
then do not create
else
create it

as simple as that
 
N

.NET Follower

hi,
just check if cokie withname already exists on the client if EXISTS
then do not create
else
create it

as simple as that
 
B

Ben Amada

..NET Follower said:
hi,
just check if cokie withname already exists on the client if EXISTS
then do not create
else
create it

as simple as that

Amit Agarwal
Software Programmer(.NET)

Hi,

Your idea is good. However, my cookie is set to expire in 1 day. When the
user visits this particular page, I want to renew the cookie so it won't
expire for another 24 hours. This is why I think I need to re-create the
cookie. What's the best way to do this? If I re-create the cookie, will it
just overwrite the old cookie? Or do I somehow need to delete the old
cookie, then create a new cookie? If this is the case, I'm not sure how to
delete the old cookie.

Thanks again,
Ben
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top