By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,136 Members | 2,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,136 IT Pros & Developers. It's quick & easy.

testing for cookies' existance

P: n/a
in ASP, this seems to work to see if a cookie exists:

If Request.Cookies("site")("district") Is Nothing Then

In asp.net, though, it gives me a 'System.NullReferenceException: Object
reference not set to an instance of an object.'

Why is that?

Looking at MSDN, my syntax seems OK:

http://msdn.microsoft.com/library/de...Cookies101.asp

-Darrel
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Fri, 26 Aug 2005 13:58:45 -0500, darrel <no*****@hotmail.com> wrote:
in ASP, this seems to work to see if a cookie exists:

If Request.Cookies("site")("district") Is Nothing Then

In asp.net, though, it gives me a 'System.NullReferenceException: Object
reference not set to an instance of an object.'

Why is that?

Looking at MSDN, my syntax seems OK:

http://msdn.microsoft.com/library/de...Cookies101.asp

-Darrel


That's because the .Cookies collection returns null/Nothing if the cookie
with the given name is not found (in this case Request.Cookies("site") is
nothing). So when the portion after that tries to call a property to get
the value, it's a null reference exception.

Check if Request.Cookies("site") is nothing first (remove the district
portion from this line of code)...then you can check the value inside that
if statement....

--
craig
Microsoft MVP - ASP/ASP.NET
Nov 19 '05 #2

P: n/a
> That's because the .Cookies collection returns null/Nothing if the cookie
with the given name is not found (in this case Request.Cookies("site") is
nothing). So when the portion after that tries to call a property to get
the value, it's a null reference exception.

Check if Request.Cookies("site") is nothing first (remove the district
portion from this line of code)...then you can check the value inside that
if statement....


aha! OK, that makes sense. And works! THanks!

-DArrel
Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.