473,486 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trouble with a simple cookie

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
Nov 21 '06 #1
3 1310
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside the box!
*************************************************
"Groove" <no***@noemail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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

Nov 21 '06 #2
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.
--


"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:uf**************@TK2MSFTNGP03.phx.gbl...
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside the box!
*************************************************
"Groove" <no***@noemail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>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


Nov 21 '06 #3
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
Groove wrote:
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.
--


"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:uf**************@TK2MSFTNGP03.phx.gbl...
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside the box!
*************************************************
"Groove" <no***@noemail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
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
Dec 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4933
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
0
5390
by: David Staschover | last post by:
I'm trying to set up sessions in perl. The session is initialized fine in session1.cgi In session2.cgi, the correct session id is returned from the cookie, but when I initialize the session, a...
2
1590
by: dave | last post by:
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...
0
874
by: Priya | last post by:
I am not able to read the cookie written through ASP from ASP.NET. I know I need to set the path of cookie correctly. When I set the path of my Cookie Response.Cookie("Test").Path = "/" in ASP...
0
1221
by: Alan Silver | last post by:
Hello, I am having a problem setting and resetting cookies. I'm sure I just doing something really stupid as this is such a basic issue, but I can find any answer. Please can someone help me? ...
2
1595
by: Owen | last post by:
I have a web app that is a mixture of ASP and ASP.NET pages. Largely the only data passed between them is via the querystring, or by reading from a database. However there is a requirement for...
3
1312
by: Kevin Blount | last post by:
I've created a quick set of test scripts, and I'm finding that cookies don't work as I would expect(i.e. the same as they do in original ASP. In original ASP I could set a cookie on one page, set...
9
2009
by: devranger | last post by:
I am using the below CURL Function and can not figure out why it is not retruning the results from the post. Can anyone take a look and tell me what I may be doing wrong? I am just not seeing...
5
13296
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.