Way to check for cookies

D

David C

Is there a way to check to see if the browser accepts cookies? I have the
following line of code that is giving an error "Object reference not set to
an instance of an object."
with the following line:

If Server.HtmlEncode(Request.Cookies("level").Value) = "admin" Then

Thanks.
David
 
G

gerry

not sure about the VB syntax , in c# it would be something like :

if ( Request.Cookies["level"]!=null &&
Server.HtmlEncode(Request.Cookies["level"].Value) == "admin" )
{
}
 
D

David C

Just curious. Why do you use Request.Cookies in one stmt and
Server.HtmlEncode(Request.Cookies... in another? Are they equivalent?

David
gerry said:
not sure about the VB syntax , in c# it would be something like :

if ( Request.Cookies["level"]!=null &&
Server.HtmlEncode(Request.Cookies["level"].Value) == "admin" )
{
}



David C said:
Is there a way to check to see if the browser accepts cookies? I have
the following line of code that is giving an error "Object reference not
set to an instance of an object."
with the following line:

If Server.HtmlEncode(Request.Cookies("level").Value) = "admin" Then

Thanks.
David
 
B

bruce barker

in c# if are short circuited

if (a && b)

if a is false, b will not be evaluated. this is not tue for vb, you will
need to do two if statements. assuming i can remember vb syntax at all:

If not Request.Cookies("level") is nothing then
if Server.HtmlEncode(Request.Cookies("level").Value) = "admin" Then

end if
end if

also have no idea why you call Server.HtmlEncode().

-- bruce (sqlwork.com)


David C said:
Just curious. Why do you use Request.Cookies in one stmt and
Server.HtmlEncode(Request.Cookies... in another? Are they equivalent?

David
gerry said:
not sure about the VB syntax , in c# it would be something like :

if ( Request.Cookies["level"]!=null &&
Server.HtmlEncode(Request.Cookies["level"].Value) == "admin" )
{
}



David C said:
Is there a way to check to see if the browser accepts cookies? I have
the following line of code that is giving an error "Object reference not
set to an instance of an object."
with the following line:

If Server.HtmlEncode(Request.Cookies("level").Value) = "admin" Then

Thanks.
David
 
D

David C

I was probably brain dead when I coded this page. Normally I just use
If Not Request.Cookies("level") Is Nothing Then
....

David
bruce barker said:
in c# if are short circuited

if (a && b)

if a is false, b will not be evaluated. this is not tue for vb, you will
need to do two if statements. assuming i can remember vb syntax at all:

If not Request.Cookies("level") is nothing then
if Server.HtmlEncode(Request.Cookies("level").Value) = "admin" Then

end if
end if

also have no idea why you call Server.HtmlEncode().

-- bruce (sqlwork.com)


David C said:
Just curious. Why do you use Request.Cookies in one stmt and
Server.HtmlEncode(Request.Cookies... in another? Are they equivalent?

David
gerry said:
not sure about the VB syntax , in c# it would be something like :

if ( Request.Cookies["level"]!=null &&
Server.HtmlEncode(Request.Cookies["level"].Value) == "admin" )
{
}



Is there a way to check to see if the browser accepts cookies? I have
the following line of code that is giving an error "Object reference
not
set to an instance of an object."
with the following line:

If Server.HtmlEncode(Request.Cookies("level").Value) = "admin" Then

Thanks.
David
 

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

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top