473,394 Members | 1,478 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,394 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 4558
> 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.