cookies question

Discussion in 'ASP .Net' started by William, Jun 3, 2005.

  1. William

    William Guest

    I'm new to ASPX. In my .aspx page I set multiple cookies from the session
    variables to the "visitor" container:


    dim cookie as HttpCookie
    cookie=new HttpCookie("visitor")
    cookie.Values.Add("cid", Session("sid"))
    cookie.Values.Add("ckeywords",Session("skeywords"))
    cookie.Values.Add("ccampaignno",Session("scampaignno"))
    cookie.Values.Add("cadgroup",Session("sadgroup"))
    cookie.Expires = Now.AddDays(365)
    response.appendcookie(cookie)


    But I need to set those cookies only if they do not exist on the computer.
    If I surround the code with if-then statement that looks like this:

    If Request.Cookies("visitor") is Nothing Then

    dim cookie ....
    ...
    ...
    response.append ...

    end if

    the browser gives me an error.

    My question is how do I check if the container "visitor" exists in cookies?

    Thank you for your time.
    William, Jun 3, 2005
    #1
    1. Advertising

  2. William

    William Guest

    Sorry -

    Forgot to include the error:

    If the cookies "visitor" do not exist the error is:

    Exception Details: System.NullReferenceException: Object reference not set
    to an instance of an object.


    "William" <> wrote in message
    news:Cc1oe.1605$...
    > I'm new to ASPX. In my .aspx page I set multiple cookies from the session
    > variables to the "visitor" container:
    >
    >
    > dim cookie as HttpCookie
    > cookie=new HttpCookie("visitor")
    > cookie.Values.Add("cid", Session("sid"))
    > cookie.Values.Add("ckeywords",Session("skeywords"))
    > cookie.Values.Add("ccampaignno",Session("scampaignno"))
    > cookie.Values.Add("cadgroup",Session("sadgroup"))
    > cookie.Expires = Now.AddDays(365)
    > response.appendcookie(cookie)
    >
    >
    > But I need to set those cookies only if they do not exist on the computer.
    > If I surround the code with if-then statement that looks like this:
    >
    > If Request.Cookies("visitor") is Nothing Then
    >
    > dim cookie ....
    > ...
    > ...
    > response.append ...
    >
    > end if
    >
    > the browser gives me an error.
    >
    > My question is how do I check if the container "visitor" exists in

    cookies?
    >
    > Thank you for your time.
    >
    >
    William, Jun 3, 2005
    #2
    1. Advertising

  3. William

    Joerg Jooss Guest

    William wrote:

    > I'm new to ASPX. In my .aspx page I set multiple cookies from the
    > session variables to the "visitor" container:
    >
    >
    > dim cookie as HttpCookie
    > cookie=new HttpCookie("visitor")
    > cookie.Values.Add("cid", Session("sid"))
    > cookie.Values.Add("ckeywords",Session("skeywords"))
    > cookie.Values.Add("ccampaignno",Session("scampaignno"))
    > cookie.Values.Add("cadgroup",Session("sadgroup"))
    > cookie.Expires = Now.AddDays(365)
    > response.appendcookie(cookie)
    >
    >
    > But I need to set those cookies only if they do not exist on the
    > computer. If I surround the code with if-then statement that looks
    > like this:
    >
    > If Request.Cookies("visitor") is Nothing Then
    >
    > dim cookie ....
    > ...
    > ...
    > response.append ...
    >
    > end if
    >
    > the browser gives me an error.
    >
    > My question is how do I check if the container "visitor" exists in
    > cookies?


    That code is fine -- the error must be at a different line in your
    code.

    Note that is not a "browser error", but a simple coding error in your
    code behind class, which you can easily debug...

    Cheers,
    --
    http://www.joergjooss.de
    mailto:
    Joerg Jooss, Jun 3, 2005
    #3
  4. William

    harafat

    Joined:
    Dec 27, 2007
    Messages:
    1
    You should use:

    If Request.Cookies("visitor") is Null rather than
    Request.Cookies("visitor") is Nothing
    harafat, Dec 27, 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. Alex Nitulescu

    Response.Cookies vs Request.Cookies

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

Share This Page