Discussion:
3rd party/<img.../> cookie problem
(too old to reply)
David Thielen
2005-09-21 03:17:04 UTC
Permalink
Hi;

The backend of this problem is in java but the problem is in the Internet
Explorer browser end (I think):

I am trying to track cookie across two of my domains. So when a user comes
to www.windwardreports.com I not only create a cookie for that domain, but I
also want to create the same cookie on windward.net.

So I created a servlet named track and in www.windwardreports.com/index.html
I placed <img src=’
Loading Image... (I do this
using a javascript that does a document.write() as the sourceid value is
unique for each contact.)

And in the servlet, my code is (image read removed):
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

Cookie [] cookies = request.getCookies();

// get the parameters
for (Iterator it=request.getParameterMap().entrySet().iterator();
it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String key = ((String) entry.getKey()).trim();
if (key.length() == 0)
continue;
String [] values = (String[]) entry.getValue();

// create a cookie
Cookie ck = new Cookie(key, values[0].trim());
ck.setDomain(“.windward.net”); // tried with and without this line
ck.setMaxAge(24 * 60 * 60 * 365 * 5);
log.info("Added cookie: " + key + "=" + values[0]);
response.addCookie(ck);
}

// return a 1x1 image – it’s in data[]
response.setContentLength(data.length);
response.setContentType("image/gif");
OutputStream out = response.getOutputStream();
out.write(data);
out.close();
}

But it’s not working as I expect. Two problems (tested from 3 computers):


Problem 1: When I go to www.windward.net (I have it there for testing) it
puts the cookies I set directly in ***@windward[1].txt. But it puts the
cookies from the tracking servlet in ***@track[1].txt
The contents of ***@track[1].txt is:
sourceid
1127147897483_633
store.windward.net/track/
1536
2950874112
30103378
1412172704
29736251
*
But this cookie is not passed back to subsequent calls to www.windward.net.

Question: How do I get it to put these cookie values in ***@windward[1].txt
instead of ***@track[1].txt.


Problem 2: When I go to www.windwardreports.com, nothing is stored unless I
go in I.E. to Tools, Internet Options, Privacy, Advanced, and check Override
automatic cookie handling.
If I do set that, then I have the same issue as problem 1 – it goes in
***@track[1].txt instead of ***@windward[1].txt.

Question: How do I get it to set these cookie values from a different domain
under standard IE settings?
--
thanks - dave
Wei-Dong XU [MSFT]
2005-09-21 06:23:22 UTC
Permalink
Hi Dave,

As I know on this cookie setting issue, we will need to use the
Cookie.setPath method to specify the root path as below:
Cookie c = new Cookie...;
c.setPath("/");

This way, Servlet will notify IE that the cookie is set for the site, not
the servlet. Then the cookie should work as expected in IE.

Please feel free to let me know if you have any further question on this
matter.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
It is my pleasure to be of assistance.

Loading...