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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top