Way to check for cookies

Discussion in 'ASP .Net' started by David C, Nov 14, 2008.

  1. David C

    David C Guest

    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
     
    David C, Nov 14, 2008
    #1
    1. Advertising

  2. David C

    gerry Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    gerry, Nov 14, 2008
    #2
    1. Advertising

  3. David C

    David C Guest

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

    David
    "gerry" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>
    >>

    >
    >
     
    David C, Nov 14, 2008
    #3
  4. David C

    bruce barker Guest

    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" wrote:

    > Just curious. Why do you use Request.Cookies in one stmt and
    > Server.HtmlEncode(Request.Cookies... in another? Are they equivalent?
    >
    > David
    > "gerry" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:...
    > >> 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
    > >>
    > >>

    > >
    > >

    >
    >
    >
     
    bruce barker, Nov 14, 2008
    #4
  5. David C

    David C Guest

    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" <> wrote in message
    news:...
    > 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" wrote:
    >
    >> Just curious. Why do you use Request.Cookies in one stmt and
    >> Server.HtmlEncode(Request.Cookies... in another? Are they equivalent?
    >>
    >> David
    >> "gerry" <> wrote in message
    >> news:...
    >> > 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" <> wrote in message
    >> > news:...
    >> >> 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
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>
    >>
     
    David C, Nov 14, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,539
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,556
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    682
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    519
  5. _Who
    Replies:
    7
    Views:
    2,721
Loading...

Share This Page