473,378 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

testing for cookies' existance

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
2 1181
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lance | last post by:
Hi, How do you test for an object existing in C#? C# seems to differentiate between 'null' and non-existance. In other languages I could test as so: if(ex.InnerException.StackTrace != null)...
0
by: Sri | last post by:
Hi I am trying to figure out how to test whether my browser cookies are enabled. I used the code from the following page...
4
by: Iain Porter | last post by:
Hi all, I have a usercontrol (a textbox with dropdown calendar that fills the textbox with the selected date) that I implement in a datagrid in a webform. On first loading the page, the datagrid's...
1
by: shank | last post by:
I need to revisit cookie testing. On the home page and every product page I write a cookie. I do this because some users enter by direct links to product pages. <%...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.