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
-----------------------------------
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
-----------------------------------