471,338 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Request.Cookies("Email").Value

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.

Jul 21 '05 #1
3 4443
> 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
}

Jul 21 '05 #2

"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
Jul 21 '05 #3
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. ;-)
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Sam Sungshik Kong | last post: by
5 posts views Thread by Peter Clark | last post: by
2 posts views Thread by Hugh Welford | last post: by
reply views Thread by Hardy Wang | last post: by
3 posts views Thread by tascien | last post: by
3 posts views Thread by Mange | last post: by
23 posts views Thread by codefire | last post: by
reply views Thread by rosydwin | last post: by

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.