Solved

Cookie appending problem

Posted on 2004-09-29
2
230 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
2 Comments
 
LVL 3

Expert Comment

by:PodExpert
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is about my first experience with programming Arduino.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now