?
Solved

Cookie appending problem

Posted on 2004-09-29
2
Medium Priority
?
236 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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
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 …
Simple Linear Regression
Suggested Courses

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