Trouble with a simple cookie

G

Groove

Hey guys - hoping you can help me out here. I'm using asp.net 2 (VB) and
trying to set and retrieve values from a cookie. I've done this a few times
before w/o a problem but I seem to be overlooking something here. I'm even
following my previous working examples and I can't see the different.

I have a page that will remember the user's settings using a cookie. Ther
Calendar Events, recent orders, etc will be displayed or hidden based upon
the checkboxes they select (but I haven't gotten that far yet). I'm getting
an error at:

Object reference not set to an instance of an object.
strMyEvents = objCookie.Values("MyEvents")

After using the code below, I tried to search the PC for a cookie and
couldn't find it which makes me think it doesn't exist. Yet, when I
response.redirect the value of the cookie just to test, it indeed finds
"True"

Any ideas??

Here's a simplified version of my code:


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

If Page.IsPostBack = False Then

Dim objCookie As HttpCookie
Dim strMyEvents As String

objCookie = Page.Request.Cookies("Intranet")


If IsNothing(objCookie) = True Then
SetCookie("True")
End If


strMyEvents = objCookie.Values("MyEvents")

lblTest.Text = strMyEvents


End If

End Sub





Protected Sub SetCookie(ByVal strMyEvents As String)

Dim objCookie As HttpCookie

objCookie = New HttpCookie("Intranet")
objCookie.Expires = DateTime.MaxValue

objCookie.Values("MyEvents") = "True"

'Response.Redirect(objCookie.Values("MyEvents"))


End Sub
 
C

Cowboy \(Gregory A. Beamer\)

The cookie should show up under the domain name you are hitting in your
temporary internet files. You have to refresh the folder after hitting the
page to see the cookie (a bit strange compared to other folders, but many of
the profile folders are not standard windows folders).

You cannot access the cookies until you redirect as the information is not
sent to the server until it is requesting another page. As it works, you are
definitely getting the cookie through.
 
G

Groove

Thanks for your help. I've triple checked everything....and still, no
cookie. Can you think of anything that might prevent cookies from being
set? I've never had problems with other sites.

WinXP Pro, IE7.
 
C

csgraham74

As far as i know there is a limit on the numebr of cookies that can be
set. i thinks its 20. I had this problem a while back. You may need to
do the response.cookies("MainCookie")("Subcookie") to set the values.

I hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top