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

cookie trouble - vb.net web page

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 = CDate("31/12/2030")
Response.Cookies("MyCookieName").Path = "/"

That works great. The cookie appears in the Temporary Files folder on disk,
with the distant expiry date as expected. Furthermore I look inside the
cookie using Notepad, and it shows the "OriginalValue" that I put in.

Now I want to read that same cookie from my ASP.NET page, using:

Dim CookieVal as String = Request.Cookies.Item("MyCookieName").Value

....which seems to work perfectly OK. It returns "OriginalValue" that I put
in there using ASP.

Now, the problem is that I cannot seem to *update* the cookie via my ASP.NET
page:

Dim c As HttpCookie = Request.Cookies.Item("MyCookieName")
c.Value = "MyNewValue"
After running the above code, I take a look inside the cookie, but the
"OriginalValue" remains. No errors occurred, it did not crash, but didn't
work either. I cannot understand why. What am I missing?

Please help!

Thanks
Owen
PS. quite urgent, so replies cc'd via email appreciated
ow************@mantix.com
Nov 21 '05 #1
2 1593
Owen,

I dont, know if it affects something however I use the Cookie as
Response.Cookies("Whatever").Expires = dt.Add(ts)

Response.Cookies("Whatever")("User") = this.TextBox1.Text

Response.Cookies("Whatever")("pw") = this.TextBox2.Text

I hope it helps something?

Cor

Nov 21 '05 #2

Jan. 7, 2005

The reason why it is not updating is that the updated cookie is not
getting sent back to the client. After you modify the cookie, you need to
manually add it to the Response.Cookies collection. Try this:

Dim c As HttpCookie = Request.Cookies.Item("MyCookieName")
c.Value = "MyNewValue"
Response.Cookies.Add(c)

This will add the cookies to the collection that is sent back to the
client. If this reply helps you, then please click on the "Yes" button just
above or below this message. Thank you and I hope this answers your question.
Joseph MCAD

"Owen" wrote:
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 = CDate("31/12/2030")
Response.Cookies("MyCookieName").Path = "/"

That works great. The cookie appears in the Temporary Files folder on disk,
with the distant expiry date as expected. Furthermore I look inside the
cookie using Notepad, and it shows the "OriginalValue" that I put in.

Now I want to read that same cookie from my ASP.NET page, using:

Dim CookieVal as String = Request.Cookies.Item("MyCookieName").Value

....which seems to work perfectly OK. It returns "OriginalValue" that I put
in there using ASP.

Now, the problem is that I cannot seem to *update* the cookie via my ASP.NET
page:

Dim c As HttpCookie = Request.Cookies.Item("MyCookieName")
c.Value = "MyNewValue"
After running the above code, I take a look inside the cookie, but the
"OriginalValue" remains. No errors occurred, it did not crash, but didn't
work either. I cannot understand why. What am I missing?

Please help!

Thanks
Owen
PS. quite urgent, so replies cc'd via email appreciated
ow************@mantix.com

Nov 21 '05 #3

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

Similar topics

6
by: Alexandre | last post by:
What's the best I can do to solve my trouble : I got a simple page index-tmp who include a code snippet who test if a cookie exist and if yes redirect to the user account page but the trouble is...
14
by: Julia | last post by:
Hi, I have the following scenario Page A.asp call page B.asp Page B.asp need to load page C.asp make some changes and return the result to IE when A.asp is first running IIS create a...
6
by: Ray | last post by:
Below is the code to save the cookie and set the expiry date of the cooki Response.Cookies.Value ="Hello" DateTime dt = DateTime.Now TimeSpan ts = new TimeSpan(0,0,10,0) Response.Cookies...
2
by: dave | last post by:
I have 2 pages... in the first page i check to see for the existance of the cookie, if found do something else set the value and set the cookie. (cookie gets set ok) I use the following code to...
3
by: Kevin Blount | last post by:
I've created a quick set of test scripts, and I'm finding that cookies don't work as I would expect(i.e. the same as they do in original ASP. In original ASP I could set a cookie on one page, set...
2
by: Kevin Blount | last post by:
I have an issue with trying to add a new name-pair to an existing cookie. Here's what I want to do: page1 - adds "loggedin=true" to cookie "Communities" adds "member_id=100" to cookie...
1
by: Vamosi Zsolt | last post by:
Hi all, I have a problem. I am beginer in cookie-making. I make one, on my laptop, where I run a web server, I can use my cookie. It operates properly independently if I use IE or Firefox. ...
4
by: Flarky | last post by:
Hi all, I have a page that has links to other pages. I want to be able to detect when the user has clicked on Back (or typed Backspace) to move back to my page. Is this possible? Thanks.
2
by: SV | last post by:
I have a login form with “Remember me on this computer” checkbox. I am creating cookie if checkbox is checked. My code is: If chk_remember.Checked = True Then Dim ckUserName As HttpCookie =...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.