views:

174

answers:

4

Client has a site at a.url.com. Client creates a cookie with host as ".url.com" and path as "/". Client redirects to us at b.url.com. Client has a coding issue that requires us to delete the cookie (long story).

The following code is not adjusting the expiration at all in our test or production environments but is working fine locally.

if (Request.Cookies["cookie"] != null)
{
  HttpCookie myCookie = new HttpCookie("cookie");
  myCookie.Expires = DateTime.Now.AddDays(-1d);
  Response.Cookies.Add(myCookie);
}

Any ideas?

A: 

is this a third party cookie? If so, the default security settings in IE will prevent cookie writing in the "internet" zone but it is allowed in your local zone.

Matt Wrock
No. They both share the same domain but just have different host a records like dog.animal.com and cat.animal.com.
Ryan Strauss
The cookie is set by a page that is a few directories down. Cookie is set by http://a.url.com/a/b/page. After the redirect (different IP and different server), our code is happening at http://b.url.com/c/page. I don't think that's important because of the cookie path set to "/" but who knows.
Ryan Strauss
A: 

Here's a hack. I am just posting this in case you find out that you cannot do what you want due to some security issue preventing you handling the issue on the second site.

You could send a request to the first site to clear the cookie via redirect and have that site bounce the user back again. Like I said, this is very hackish (or I suppose marketing would call it inter-site cooperative security feature).

Hopefully, there's a better approach, but at least you have an alternative if no other ones are forthcoming.

A: 

Hi Jon,

If you cannot get it working in C# you might want to consider seeing if you can manipulate the cookies in javascript.

Gary

gary
A: 

We've figured it out. We needed to add one line of code to manually set the domain. Makes total sense now.

if (Request.Cookies["cookie"] != null)
{
  HttpCookie myCookie = new HttpCookie("cookie");
  myCookie.Domain = ".url.com";
  myCookie.Expires = DateTime.Now.AddDays(-1d);
  Response.Cookies.Add(myCookie);
}
Ryan Strauss
This exactly i was going to suggest.
Neil