Way to check for cookies

  • Thread starter Thread starter David C
  • Start date Start date
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
 
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" )
{
}
 
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
 
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
 
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
 
Back
Top