473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.C ookies 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.Co okies["Cookie1"];
HttpCookie Cookie2 = Page.Request.Co okies["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("Coo kie1");
}

Cookie1.Value = NewVal1;
Cookie1.Expires = DateTime.MaxVal ue;

Page.Response.C ookies.Add(Cook ie1);

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

Cookie2.Value = NewVal2;
Cookie2.Expires = DateTime.MaxVal ue;

Page.Response.C ookies.Add(Cook ie2);
}
--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Nov 19 '05 #1
1 1883
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******** *******@TK2MSFT NGP09.phx.gbl.. .
I have a page that uses two cookies.

On postback, both cookies are updated and added back into the
Page.Response.C ookies 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.Co okies["Cookie1"];
HttpCookie Cookie2 = Page.Request.Co okies["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("Coo kie1");
}

Cookie1.Value = NewVal1;
Cookie1.Expires = DateTime.MaxVal ue;

Page.Response.C ookies.Add(Cook ie1);

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

Cookie2.Value = NewVal2;
Cookie2.Expires = DateTime.MaxVal ue;

Page.Response.C ookies.Add(Cook ie2);
}
--
-----------------------------------
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
259
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 using cookies that it writes to on the client side (using javascript). What happens sometimes it that the application forces the user back to the authentication page ( the login page). I suspect this has something to do with the limit on the...
0
989
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++) { MyCookie = MyCookieColl; if (MyCookie.Name == "AspenUser") { MyCookie = ddTZ.SelectedValue; MyCookie = ddTZ.SelectedItem.Text;
4
2328
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 at all. I'm probably missing something but I can't find what. Any help will be really appreciated. Here is the Code I execute to Create my Cookie: HttpCookie httpCookie = new HttpCookie("MyCookie");
2
3726
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 a DLL, which is why I use HttpContext)... HttpCookie cookie = new HttpCookie("fred", "ferret");
3
1222
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 following Session("MyObj")=value cookies have to be enabled on the client browser. Is that true? If true where can i find that cookie in my pc directories? About the sample: there's 2 .aspx pages with just 1 label on the first page.
2
1599
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 one part to communicate via a cookie. (Please dont ask me to go into why, I don't have time). In my ASP page, I created a cookie and put a value in it: Response.Cookies("MyCookieName") = "OriginalValue" Response.Cookies("MyCookieName").Expires...
1
1603
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 built-in methods). I have my own database table for user info, and people can register on the site, and then log in. If they haven't logged in, they are considered a guest and I store their name as "guest" in a sessions table along with some other info...
17
4169
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 hosted at two.com If I view the frameset from one.com in Firefox, all works well with the content from two.com. But if trying to view this using IE (with standard security settings), the cookie set by two.com is not accessible.
16
2972
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 something that PHP guys would know the answer to. I can't think of a more appropriate forum to try. I've heard the ASP and JSP guys aren't as friendly ;-) Let's say we have a HTML page from domain example.com, and that HTML page makes a request to...
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8490
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.