Cookie Trouble --> disappearing

  • Thread starter Thread starter dave
  • Start date Start date
D

dave

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 read and write the cookie..
READ..
Dim stmp As String
Dim c As HttpCookie =
HttpContext.Current.Request.Cookies("HD")
If Not c Is Nothing Then
stmp = c(Key)
Else
stmp = ""
End If
Return stmp

WRITE
Dim c As New HttpCookie("HD")
c("DialogTypeID") = DialogTypeID.ToString
c.Expires = DateTime.Now.AddYears(1)
HttpContext.Current.Response.Cookies.Add(c)



Now i navigate to a second page which looks for a cookie
of a differnt name and reads the value. The following
code...

Dim stmp As String
Dim c As HttpCookie =
HttpContext.Current.Request.Cookies("HD2")
If Not c Is Nothing Then
stmp = c(Key)
Else
stmp = ""
End If
Return stmp

Now when i navigate back to the first page the first
cookie is gone. I look in my localhost cookies and it is
no longer in the cookie file. PLEASE tell me what is
going on.

please.
thank you in advance...

dave
 
Hi,

if you dont set any of the cookies properties (Domain,Expires...) the
default is that cookie will be available for the current page. if you
navigate to other page the cookie die. when you use the Back button the
browser use cache version of the page. no call is made to the server so
no new cookie creat and the old one already vanished.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
DId you also "write" cookies in the second web form? Additionally, when
will you write the cookies, after find that stmp is empty?

Luke

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top