Weird cookie problem

  • Thread starter Thread starter Todd
  • Start date Start date
T

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!!!
 
Hi,
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
 
Back
Top