HttpContext.Current.Request.Cookies error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
How about trying something like

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

Peter
 
you need to check if the "Master" cookie exists before looking for a
value in it.

-- bruce (sqlwork.com)
 
Back
Top