retrieve a cookie from a second page

evaleah

Well-known member
Joined
May 14, 2003
Messages
55
Hi Gang!

I have a page where if a case is true I create a cookie. That part works great. However, I later want to retrieve the cookie but from a different page. When I call the cookie on the second page the value is back to "". Is this possible to do?

I havent set the expire property on the cookies on Page1. I wanted them to expire at the end of the session. Does that mean actually they are expiring when I navigate away from the page?

The code to get the cookie back I am using on Page2 is:
Code:
Dim ckMember As System.Web.HttpCookie = New HttpCookie("Member")

If Not ckMember Is Nothing Then
    With ckMember
        If .Item("LastName") <> "" Then
              objLastName.Value = CStr(Trim(.Item("LastName")))
        End If
     End With
End If

Thanks!
Eva
 
try using response and request.Cookies

Code:
Use this to set cookie
Response.Cookies("members").Value = <value>
Response.Cookies("members").Path = "/"
Response.Cookies("members").Expires = DateTime.Now.AddMinutes(1)

it also looks like your putting a custom class in your cookie ??
Where did the .lastname come from ??
If you doing something like this
Code:
Dim <variable> as Custom_Class_Person
<valiable>.lastname = "yad yad"

Cookie.Value = <variable>

Then you would need to assign the calue of the cookie to a new instance of that custom class.
Post your code where you make the cookie so I can look at it please.
 
Actually, the syntax I am using is what MS is saying is more correct now than trying to use the old ASP style request and response objects. So "LastName" in this case is the key name of a cookie called "Member".
 
Syntax arguments aside you will still need to use the Response / Request objects to read and write the cookies to /from the browser.

[VB]
response.cookies.add(ckMember) Send cookie to browser

ckMember = request.cookies("Member") Read cookie from browser
[/code]

...or similar no MSDN installed at this PC;)
 
Last edited by a moderator:
Back
Top