Cookie update problem with multiple cookies on a page.

K

Ken Varn

I have a page that uses two cookies.

On postback, both cookies are updated and added back into the
Page.Response.Cookies collection. For some reason, only the first cookie is
actually updated on the client. The second cookie contains its original
value on postback, not the new value.

Can someone tell me why I can't update the second cookie?

Here is a code sample.

{
String Val1, Val2;
String NewVal1, NewVal2;

HttpCookie Cookie1 = Page.Request.Cookies["Cookie1"];
HttpCookie Cookie2 = Page.Request.Cookies["Cookie2"];

if (Cookie1 != null)
{
Val1 = Cookie1.Value;
}
else
{
Val1 = "default string"; }
}

if (Cookie2 != null)
{
Val2 = Cookie2.Value;
}
else
{
Val2 = "default string"; }
}


NewVal1 = "NewString";
NewVal2 = "NewString";

if (Cookie1 == null)
{
Cookie1 = new HttpCookie("Cookie1");
}

Cookie1.Value = NewVal1;
Cookie1.Expires = DateTime.MaxValue;

Page.Response.Cookies.Add(Cookie1);

if (Cookie2 == null)
{
Cookie2 = new HttpCookie("Cookie2");
}

Cookie2.Value = NewVal2;
Cookie2.Expires = DateTime.MaxValue;

Page.Response.Cookies.Add(Cookie2);
}
--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
K

Ken Varn

I think I found the problem. I had some JavaScript updating the same cookie
and it appears as though the JavaScript cookie crumb string format is not
the same as that used by ASP.NET.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top