Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 haven't 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:

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

Posted

try using response and request.Cookies

 

'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

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.

Posted
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".
  • Administrators
Posted (edited)

Syntax arguments aside you will still need to use the Response / Request objects to read and write the cookies to /from the browser.

 

response.cookies.add(ckMember)                'Send cookie to browser

ckMember = request.cookies("Member")      'Read cookie from browser

 

...or similar no MSDN installed at this PC;)

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...