473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 4555
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Sam Sungshik Kong | last post by:
Hello! I use Python for ASP programming. I found something weird. Response.Write(Request("something")) It draws "None" when there's no value for something. Actually I expect "" instead of...
5
by: Peter Clark | last post by:
Think of something like MyYahoo: a personalized portal with news aggregator, weather forecast, comics, etc. Now instead of visiting a web site, think of all of it being sent daily as an email. It...
2
by: Hugh Welford | last post by:
Hi I cant seem to get the LIKE oprator to work in asp. I am trying to verify e-mail input format by using request("email") like "*@*.*" but it returns "sub or function not defined" any...
0
by: Hardy Wang | last post by:
Hi, I have an application which encrypts some certian link to format like:...
3
by: tascien | last post by:
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...
3
by: Mange | last post by:
I'm using WebRequest class to access a PHP script, but keep getting a 400 error from the server when calling the GetResponse() method. I have added the url to the script in the bypass list in...
23
by: codefire | last post by:
Hi, I am trying to get a regexp to validate email addresses but can't get it quite right. The problem is I can't quite find the regexp to deal with ignoring the case james..kirk@fred.com, which...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: MrCorbeaux | last post by:
My "Email a Webpage" form works find except when the end user receives the email, the URL is text only and not a hyperlink. The "Email a Page" form calls the URL from the previous page using: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.