Solved

Cookie appending problem

Posted on 2004-09-29
2
234 Views
Last Modified: 2010-04-17
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?
0
Comment
Question by:garyervin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:PodExpert
ID: 12183546
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.
0
 

Accepted Solution

by:
sudarshan_sharma22 earned 125 total points
ID: 12214915
Cookies are appended into the Headers. Hence there can be more then one cookie.
Hence when ever you do (Response.Cookies("loc") = locID) a cookie with name "loc" is appened to the headers.

Hence the result that you get two cookies with the same name "loc". So what you need to do is that delete the first cookies if its present or you need to modify that cookie.



An alternate way to your problem is to use the header "Referer", that gives the URL from which the page is viisted. (this will directly give you the url of the page and then u need to decode that appropriately ( from 1 to 12 whatever might be ur logic).

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question