Link to home
Start Free TrialLog in
Avatar of garyervin
garyervin

asked on

Cookie appending problem

I am modifying an ASP program and need to add a cookie which will keep track of where a person as last visited.  Lets say the Cookie will be called loc.

With the following code getting executed whenever a user changes his location:

        Response.Cookies("loc") = locID
                  Response.Cookies("loc").Expires = Now() + 50

locID is a varible which can run from 1 to 12.  On the first save of this cookie, it does OK.  After than it appends the came name in the cookie with the new value.   Thus you have after the second selection, 2 enties for loc.  In retrieving the cookie for loc, it reads the first occurrence.  What is the way to prevent having the multiple entries for the same cookie?
Avatar of PodExpert
PodExpert

Every cookies is defined by following information:

- name
- domain (default: domain of the server, e.g. yahoo.com)
- path (default: root - all scripts in the domain have access to the cookie)

If you are creating cookies from different domains [or subdomains!] (your scripts are in different domains), then it might be the problem - in fact, you are creating two different cookies (with the same name, but different domains). Try explicitly change the Domain and Path properties of the cookies to information, that is common to all scripts. If your scripts are in domains aaa.domain.com and bb.domain.com, then the domain should be set to domain.com. Path should be set to "/".

Regards.
P.
ASKER CERTIFIED SOLUTION
Avatar of sudarshan_sharma22
sudarshan_sharma22

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial