Home All Groups Group Topic Archive Search About
Author
10 Sep 2006 12:18 AM
Todd
I'm writing a cookie in one asp.net page, then trying to read that new
value in another.

Problem is, the saved value disappears when the cookie code calls it!

Here's the code...

SETTING THE COOKIE
*********************************************************
Dim i As String = Request.QueryString("passedVal").ToString
Dim aCookie As HttpCookie = Request.Cookies("MyCookie")
aCookie.Values("value1") = aCookie.Values("value1") + 1
aCookie.Values("value2") = aCookie.Values("value2").ToString & i & ";"
Response.Redirect("page2.aspx")


READING THE COOKIE
*************************************************************
Dim aCookie As HttpCookie = Request.Cookies("MyCourses")
Dim MyVal1 As Integer = aCookie.Values("value1")
Dim MyVal2 as String = aCookie.Values("value2")


No matter what I do, MyVal2 is always a zero-length string (""). I am
expecting somthing like "1;2;3;4;" depending upon user input. The
values should get tacked on the end.

But it just aint workin!!!!

I've tested this on several machine, different browsers the result is
the same. Values set in page1 are gone when page2 trys to read it.

HELP!!!

Author
10 Sep 2006 11:07 AM
Laurent Bugnion
Hi,

Todd wrote:
Show quote
> I'm writing a cookie in one asp.net page, then trying to read that new
> value in another.
>
> Problem is, the saved value disappears when the cookie code calls it!
>
> Here's the code...
>
> SETTING THE COOKIE
> *********************************************************
> Dim i As String = Request.QueryString("passedVal").ToString
> Dim aCookie As HttpCookie = Request.Cookies("MyCookie")
> aCookie.Values("value1") = aCookie.Values("value1") + 1
> aCookie.Values("value2") = aCookie.Values("value2").ToString & i & ";"
> Response.Redirect("page2.aspx")

You are getting an array from the request, and then modify the array's
values. However, if you want to pass the cookies to the browser (where
they will be stored), you must write them using Response.Cookies.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch

AddThis Social Bookmark Button