cookie trouble - vb.net web page

O

Owen

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
(e-mail address removed)
 
C

Cor Ligthert

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

cookie troubles 1
Unable to retrieve cookie set via javascript 2
Cookie with double name 1
cookie trouble 3
Can i have a cookie 3
Can't Update of Cookie 2
Cookie isn't being read 1
Cookie problem 1

Top