473,396 Members | 1,865 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,396 software developers and data experts.

Can't Update of Cookie

Seb
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");
httpCookie.Expires = DateTime.Now.AddDays(30);
httpCookie.Path = "/";
httpCookie.Value = "MyInitValue";
Response.Cookies.Add(httpCookie);

If I call back the Page and check what is in
Request.Cookies["MyCookie"].Value it returns "MyInitValue".

Now I try to update the cookie here is the code:
Response.Cookies.Set(Request.Cookies["MyCookie"]);
Response.Cookies["NewBasket"].Value = "MyNewValue";
Response.Cookies["NewBasket"].Expires = DateTime.Now.AddDays(30);

After this code is executed when I check
Request.Cookies["MyCookie"].Value it returns always "MyInitValue".

Can anybody see what I'm missing ?

I will appreciate your help.

Kind regards.

Sébastien.
Nov 19 '05 #1
4 2301
Request.Cookies is used for accessing the value only, while Response.Cookies
is used for setting values (or updating, in your case).

You need to use Response.Cookies to update the cookie, and not
Request.Cookies.

--
Damian

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 19 '05 #2
Request.Cookies is used for accessing the value only, while Response.Cookies
is used for setting values (or updating, in your case).

You need to use Response.Cookies to update the cookie, and not
Request.Cookies.

--
Damian

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 19 '05 #3
Nevermind, I thought you were using Request.Cookies as the update. My
fault.

--
Damian

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 19 '05 #4
Nevermind, I thought you were using Request.Cookies as the update. My
fault.

--
Damian

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 19 '05 #5

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

Similar topics

4
by: Geoff May | last post by:
I'm busy rewriting by F1 database and I want to use cookies to store various user definable views, (basically so that when the visitor returns to a specific page, that page will redisplay in the...
1
by: Mike | last post by:
Hello, I can't find any javascript that reads and writes cookies with keys, so that it is compatible with ASP (I want to read and write cookies from both javascript and ASP) for example in...
0
by: James | last post by:
Hi, I am trying to update a cookie value using the following code: Response.Cookies.Values = "VALUE"; This actually deletes the cookie rather than updating. I have set an expiry date for...
12
by: Jason Shohet | last post by:
I've asked this on the asp ng, but couldn't get any advice, wondering if anyone here can help... GOAL: place a .NET cookie, in a user's cookie folder, containing the machinename of the current...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
0
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...
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...
4
by: D. | last post by:
Hi, I defined some cookies in order to pass values between pages in my application. The problem is that when i request them with: cookie = Request.Cookies("mycookie") x = cookie.Value (suppose...
1
by: rajunarender01 | last post by:
hi i am working with the usercontrol and want to update the cookie value in the user control how to do it
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.