473,506 Members | 17,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpContext.Current.Request.Cookies error

Hi,

I have a page which creates a cookie and adds it to the cookies collection.
On the next page it is retrieved, but trying to do so throws an exception,
"Object reference not set to an instance of an object".

The line it fails on is:

if (HttpContext.Current.Request.Cookies["Master"]["UserID"] != null)

As I am testing to see if it is null, I wouldn't expect it to throw a
NullReference exception.

Anyone have any ideas?
Mar 21 '07 #1
2 8387
How about trying something like

if (HttpContext.Current.Request !=null)
if( etc., etc.

Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"cashdeskmac" wrote:
Hi,

I have a page which creates a cookie and adds it to the cookies collection.
On the next page it is retrieved, but trying to do so throws an exception,
"Object reference not set to an instance of an object".

The line it fails on is:

if (HttpContext.Current.Request.Cookies["Master"]["UserID"] != null)

As I am testing to see if it is null, I wouldn't expect it to throw a
NullReference exception.

Anyone have any ideas?
Mar 21 '07 #2
you need to check if the "Master" cookie exists before looking for a
value in it.

-- bruce (sqlwork.com)

cashdeskmac wrote:
Hi,

I have a page which creates a cookie and adds it to the cookies collection.
On the next page it is retrieved, but trying to do so throws an exception,
"Object reference not set to an instance of an object".

The line it fails on is:

if (HttpContext.Current.Request.Cookies["Master"]["UserID"] != null)

As I am testing to see if it is null, I wouldn't expect it to throw a
NullReference exception.

Anyone have any ideas?
Mar 21 '07 #3

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

Similar topics

0
1276
by: John | last post by:
I'm trying to create a context object similar to the HttpContext that could be used by business objects independent of the origin or the call (ASP.NET or standalone). So I started out by...
2
1912
by: Francois Malgreve | last post by:
hello guys, I have some helper class in my ASP.NET pplication who basically contains static methods. I used them as helper methods to do small jobs that I can use at many places in my code. ...
1
6477
by: josephpage | last post by:
I have a Visitor class that is defined in a class library. The class has lots of parameters that are pulled from the QueryString, the ReferrerUrl, Cookies, the Session object, etc... I would...
3
2930
by: goelajay | last post by:
I have a web service where I am using System.Web.HttpContext.Current.Session. If I post an xmlrequest using an aspx page, I can referrence the Session value, but If I am posting it from say a vbs...
3
2953
by: Steve Franks | last post by:
Is there a way I can extend the HttpContext or one of its subclasses to include a property that exposes a custom class of mine to all ASP.NET pages? More specifically, I'd like to use a...
2
2124
by: | last post by:
Today I learned that creating cookies inside of a custom class in ASP.NET 2.0 requires that you prefix it with HttpContext.Current..., e.g. : ...
0
2174
by: Rodusa | last post by:
I am trying to replace cookies with the new "Asp.net 2.0 profiles" in my shopping cart application, but I am having trouble to access profile properties using HttpContext.Current.Profile. I can...
2
11932
by: Dave | last post by:
After some digging, I discovered HttpContext.Current.Session is null when trying to access a session variable, username, in my upload.cs code which is in the App_Code folder. I just determined...
3
13415
by: Brett R. Wesoloski | last post by:
I am having problems using HttpContext.Current.Request.Url.Host. I have some code that does this... if (HttpContext.Current != null) { subdomain = HttpContext.Current.Request.Url.Host; }
0
7220
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
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
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...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.