473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cookie update problem with multiple cookies on a page.

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
-----------------------------------
Nov 19 '05 #1
1 1870
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
-----------------------------------
"Ken Varn" <nospam> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
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
-----------------------------------

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rakesh Roberts | last post by:
I think I have a very interesting cookie problem. I use form authentications on my application. Through out my application I started using a toggle control that persists its value for the session...
0
by: Denver Developer | last post by:
I have a cookie that is set by a previous ASP page that I wish to update with the following logic. MyCookieColl = Request.Cookies; for (loop1 = 0; loop1 < MyCookieColl.Count ; loop1++) {...
4
by: Seb | last post by:
Hi All, I'm a bit confused. I simply try to create a new Cookie. And Update my cookie later when another call is made to my Page. The cookie creation works properly, but the update does not work...
2
by: Alan Silver | last post by:
Hello, I have discovered that if I try and add a cookie when one by that already exists, nothing happens. No error, but the cookie is not set to the new value. For example (this is running in...
3
by: rodchar | last post by:
Hey all, I'm trying to gain more knowledge about state management and I found an MSDN Help article about cookies. I posted the short sample below. From what I read in the article if you do the...
2
by: Owen | last post by:
I have a web app that is a mixture of ASP and ASP.NET pages. Largely the only data passed between them is via the querystring, or by reading from a database. However there is a requirement for...
1
by: .NET Developer | last post by:
I'm having an issue that hopefully someone here can help me out with. First a quick explanation: I'm managing users of my site in a fairly custom way. (in other words I'm not using asp.net's...
17
by: Bruno | last post by:
I have a feature that is hosted on a different domain from the primary one in a frame, and need to retain values in a cookie. example: A web page at one.com contains a frame which has a page...
16
by: Stevo | last post by:
I'm guessing this is a laughably obvious answer to many here, but it's not to me (and I don't have a server or any knowledge of PHP to be able to try it). It's not strictly a PHP question, but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.