What's the proper way of reading cookies? Request.Cookies("mycook") doesnt work

Discussion in 'ASP .Net' started by user, Mar 31, 2007.

  1. user

    user Guest

    Hi everyone,

    May I know the standard way of reading in cookies in ASP.net using
    VB.net?

    In classic asp, i can do this:

    If request.cookies("user") = "abc" then

    blah blah

    end if

    But if i were to do the same in asp.net,

    I would hit an ugly error.

    What is the proper way of detecting cookies?

    Thanks
    user, Mar 31, 2007
    #1
    1. Advertising

  2. user

    Masudur Guest

    On Mar 31, 10:08 am, "user" <> wrote:
    > Hi everyone,
    >
    > May I know the standard way of reading in cookies in ASP.net using
    > VB.net?
    >
    > In classic asp, i can do this:
    >
    > If request.cookies("user") = "abc" then
    >
    > blah blah
    >
    > end if
    >
    > But if i were to do the same in asp.net,
    >
    > I would hit an ugly error.
    >
    > What is the proper way of detecting cookies?
    >
    > Thanks


    Hi........

    Here is a quick link.... from asp.net quick start...
    http://quickstarts.asp.net/QuickStartv20/aspnet/doc/applications/state.aspx#cookies

    Thanks...
    Masudur
    http://www.kaz.com.bd
    http://munnacs.blogspot.com
    Masudur, Mar 31, 2007
    #2
    1. Advertising

  3. user

    Mark Rae Guest

    "user" <> wrote in message
    news:...

    > In classic asp, i can do this:
    >
    > If request.cookies("user") = "abc" then
    >
    > blah blah
    >
    > end if
    >
    > But if i were to do the same in asp.net,
    >
    > I would hit an ugly error.


    Would you...? What ugly error would you hit...?

    > What is the proper way of detecting cookies?


    If Request.Cookies("user") = "abc" Then
    ' blah blah
    End If
    Mark Rae, Mar 31, 2007
    #3
  4. Re: What's the proper way of reading cookies? Request.Cookies("mycook")doesnt work

    user wrote:
    > Hi everyone,
    >
    > May I know the standard way of reading in cookies in ASP.net using
    > VB.net?
    >
    > In classic asp, i can do this:
    >
    > If request.cookies("user") = "abc" then
    >
    > blah blah
    >
    > end if
    >
    > But if i were to do the same in asp.net,
    >
    > I would hit an ugly error.
    >
    > What is the proper way of detecting cookies?
    >
    > Thanks
    >


    The difference in .NET is that what you get from the Request.Cookies
    collection is an HttpCookie object instead of a string. If the cookie
    doesn't exist, you get a null reference instead of an empty string.

    HttpCookie user = Request.Cookies("user");
    if (user != null && user.Value == "abc") {
    //blah blah
    }

    --
    Göran Andersson
    _____
    http://www.guffa.com
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Mar 31, 2007
    #4
    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. Eric Layman

    What is the proper way to use cookies?

    Eric Layman, Apr 1, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    322
    Alvin Bruney [MVP]
    Apr 1, 2007
  2. mhshpk
    Replies:
    0
    Views:
    546
    mhshpk
    Jul 18, 2007
  3. Replies:
    3
    Views:
    432
    alex23
    May 27, 2008
  4. _Who
    Replies:
    7
    Views:
    2,653
  5. Replies:
    1
    Views:
    153
    Josh Twist
    Feb 10, 2006
Loading...

Share This Page