Request.Cookies("Email").Value

  • Thread starter Thread starter tascien
  • Start date Start date
T

tascien

I cannot believe that this code causes an error:

Dim MyCookie as string = Request.Cookies("Email").Value

Object reference not set to an instance of an object.

If the cookie is found, it works, if the cookie is not found, the error
above is triggered. and i can't just do this:

Dim MyCookie as string = Request.Cookies("Email")

Value of type 'System.Web.HttpCookie' cannot be converted to 'String'.

So, how do you check for cookies? Keeping in mind that the cookie may
exist, or not...

Thanks.
 
I cannot believe that this code causes an error:
Dim MyCookie as string = Request.Cookies("Email").Value

Object reference not set to an instance of an object.
I don't know about VB but maybe something like this (pseude code but you get
the idea).

if (Request.Cookies("Email")!=NULL) {
string = Request.Cookies("Email").Value
}
 
"Olaf Baeyens"
I don't know about VB but maybe something like this (pseude code but you
get
the idea).

if (Request.Cookies("Email")!=NULL) {
string = Request.Cookies("Email").Value
}

If Not Request.Cookies("Email") Is Nothing then
dim mycookie as string = Request.Cookies("Email").Value
End if

Cor
 
If Not Request.Cookies("Email") Is Nothing then
dim mycookie as string = Request.Cookies("Email").Value
End if
Nice and now try to avoid to request 2 times. ;-)
 
Back
Top