Cookies duplicating themselves

  • Thread starter Thread starter Darren.Ratcliffe
  • Start date Start date
D

Darren.Ratcliffe

Hi everyone

I'm using v 2.0 of the framework with C# and am developing a web
application.

I am finding that my cookie names are duplicating themselves over and
over again, for example when I write out all the cookie keys and
values, I am getting the following:

CookieA: Apple
CookieB: Banana
CookieC: Carrott
CookieA: Apple
CookieB: Banana
CookieC: Carrott

I don't understand why this is happening - but I feel there may be
some of you out there that know exactly what has caused this
problem... or at least I hope!

Any pointers are most appreciated.

Many thanks

Darren
 
What method are you using to add the cookies to the cookie collection? Are
you using insert? If so then it may simply be appending the added cookie(s)
onto the existing collection. Before, you may check to see if CookieA exists
at some ordinal position by doing something like,
Resposnse.Cookie["CookieA"] = , some cookie
 
Here is a cookie wrapper I had:


public static void SetCookieValue(Page p, string cookieName, string
cookieValue, string subKey, TimeSpan expiresTimeSpan)

{

bool subKeyWasSupplied = false;

if (null != subKey)

{

if (subKey.Length > 0)

{

subKeyWasSupplied = true;

}

}

_currentTimeSpan = expiresTimeSpan;

if (p.Request.Cookies[cookieName] == null)

{

CreateCookie(p, cookieName);

}

HttpCookie aCookie = p.Request.Cookies[cookieName];

if (subKeyWasSupplied)

{

aCookie.Values[subKey] = cookieValue;

}

else

{

aCookie.Value = cookieValue;

}



aCookie.Expires = DateTime.Now.Add(_currentTimeSpan);

p.Response.Cookies.Add(aCookie);

}
 
Hi Mark, sloan

I'm using Response.Cookies.Set - does that make any difference?

I'm also doing the checks to see if the cookies already exist but
still not working.

The really strange thing is that on my local machine I new have this
working fine (again) - but when I publish to my live server, cookies
are dropping at random.

I've tried adding a loop in my master page to reset ALL the cookies on
Page_Load but this doesn't even seem to get around the problem!

Very strange this one - very strange indeed!

Darren

What method are you using to add the cookies to the cookie collection? Are
you using insert? If so then it may simply be appending the added cookie(s)
onto the existing collection. Before, you may check to see if CookieA exists
at some ordinal position by doing something like,
Resposnse.Cookie["CookieA"] = , some cookie

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006




Hi everyone
I'm using v 2.0 of the framework with C# and am developing a web
application.
I am finding that my cookie names are duplicating themselves over and
over again, for example when I write out all the cookie keys and
values, I am getting the following:
CookieA: Apple
CookieB: Banana
CookieC: Carrott
CookieA: Apple
CookieB: Banana
CookieC: Carrott
I don't understand why this is happening - but I feel there may be
some of you out there that know exactly what has caused this
problem... or at least I hope!
Any pointers are most appreciated.
Many thanks
Darren- Hide quoted text -

- Show quoted text -
 
Back
Top