When are cookies created?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Blount

    When are cookies created?

    I've setup a method (C#) that I can call, passing it a cookie name,
    then a name-value pair. The idea is that as I can't append to a cookie,
    I read the cookie value, append by name=pair to the end and write it
    back... which works fine for adding a single name-value pair on a page.

    The problem is, I want/need to add multiple name-values pairs, the
    number of which changing between pages (some might have 3, another 8).
    In my test scripts I've found a major problem when trying to add even 2
    pairs on a single page.

    The problem is this:

    - the first time I call my method, it checks the current cookie value,
    which is say "loggedin=t rue"
    - it then appendsthe name-value pair passed to the method ("name" and
    "kevin") as a new string, i.e. "loggedin=true& name=kevin"
    - I think write the new string as the value of the cookie and return to
    my aspx calling page

    the second time I call the method, I check the current cookie value
    again (naturally), which I'd expect to be "loggedin=true& name=kevin",
    but in fact it's the original value of just "loggedin=true" . This means
    that when I add the second passed name-value pair (say, "gender" and
    "male") the final value of the cookie is "loggedin=true& gender=male".

    I say 'final', cause if I check the value of the cookie on my calling
    page (i.e. without refreshing or going to another page), the value of
    the cookies is STILL the original one, not the one I did with my
    Response.Cookie s(...) or Response.Cookie s.Set(...) or any of the other
    properties I've tried.

    So, back to my original question: when exactly do cookies get written
    to the browser? It seems to me that it's only when the current page is
    reloaded or moved away from. Can that really be the case??

    Many thanks

  • clintonG

    #2
    Re: When are cookies created?

    The cookie is passed in the response of the header. You need to learn how to
    reference the Server Variables collection.

    <%= Clinton Gallagher
    NET csgallagher AT metromilwaukee. com
    URL http://www.metromilwaukee.com/clintongallagher/



    "Kevin Blount" <kevin.blount@g mail.comwrote in message
    news:1153523896 .038422.298800@ m79g2000cwm.goo glegroups.com.. .
    I've setup a method (C#) that I can call, passing it a cookie name,
    then a name-value pair. The idea is that as I can't append to a cookie,
    I read the cookie value, append by name=pair to the end and write it
    back... which works fine for adding a single name-value pair on a page.
    >
    The problem is, I want/need to add multiple name-values pairs, the
    number of which changing between pages (some might have 3, another 8).
    In my test scripts I've found a major problem when trying to add even 2
    pairs on a single page.
    >
    The problem is this:
    >
    - the first time I call my method, it checks the current cookie value,
    which is say "loggedin=t rue"
    - it then appendsthe name-value pair passed to the method ("name" and
    "kevin") as a new string, i.e. "loggedin=true& name=kevin"
    - I think write the new string as the value of the cookie and return to
    my aspx calling page
    >
    the second time I call the method, I check the current cookie value
    again (naturally), which I'd expect to be "loggedin=true& name=kevin",
    but in fact it's the original value of just "loggedin=true" . This means
    that when I add the second passed name-value pair (say, "gender" and
    "male") the final value of the cookie is "loggedin=true& gender=male".
    >
    I say 'final', cause if I check the value of the cookie on my calling
    page (i.e. without refreshing or going to another page), the value of
    the cookies is STILL the original one, not the one I did with my
    Response.Cookie s(...) or Response.Cookie s.Set(...) or any of the other
    properties I've tried.
    >
    So, back to my original question: when exactly do cookies get written
    to the browser? It seems to me that it's only when the current page is
    reloaded or moved away from. Can that really be the case??
    >
    Many thanks
    >

    Comment

    • Kevin Blount

      #3
      Re: When are cookies created?

      Any chance you could give me a little more info? what specifically in
      Server Variables should I be looking for? Do you have a site that
      explains what you refer to?

      Thanks for the response though, I'll check them out myself and see what
      I can find, thoguh I've spent so long looking at this issue that any
      help would be much appreciated.

      kevin

      clintonG wrote:
      The cookie is passed in the response of the header. You need to learn how to
      reference the Server Variables collection.
      >
      <%= Clinton Gallagher
      NET csgallagher AT metromilwaukee. com
      URL http://www.metromilwaukee.com/clintongallagher/
      >
      >
      >
      "Kevin Blount" <kevin.blount@g mail.comwrote in message
      news:1153523896 .038422.298800@ m79g2000cwm.goo glegroups.com.. .
      I've setup a method (C#) that I can call, passing it a cookie name,
      then a name-value pair. The idea is that as I can't append to a cookie,
      I read the cookie value, append by name=pair to the end and write it
      back... which works fine for adding a single name-value pair on a page.

      The problem is, I want/need to add multiple name-values pairs, the
      number of which changing between pages (some might have 3, another 8).
      In my test scripts I've found a major problem when trying to add even 2
      pairs on a single page.

      The problem is this:

      - the first time I call my method, it checks the current cookie value,
      which is say "loggedin=t rue"
      - it then appendsthe name-value pair passed to the method ("name" and
      "kevin") as a new string, i.e. "loggedin=true& name=kevin"
      - I think write the new string as the value of the cookie and return to
      my aspx calling page

      the second time I call the method, I check the current cookie value
      again (naturally), which I'd expect to be "loggedin=true& name=kevin",
      but in fact it's the original value of just "loggedin=true" . This means
      that when I add the second passed name-value pair (say, "gender" and
      "male") the final value of the cookie is "loggedin=true& gender=male".

      I say 'final', cause if I check the value of the cookie on my calling
      page (i.e. without refreshing or going to another page), the value of
      the cookies is STILL the original one, not the one I did with my
      Response.Cookie s(...) or Response.Cookie s.Set(...) or any of the other
      properties I've tried.

      So, back to my original question: when exactly do cookies get written
      to the browser? It seems to me that it's only when the current page is
      reloaded or moved away from. Can that really be the case??

      Many thanks

      Comment

      • Kevin Blount

        #4
        Re: When are cookies created?

        I forgot to ask what "The cookie is passed in the response of the
        header." means in laymans terms.

        Kevin
        clintonG wrote:
        The cookie is passed in the response of the header. You need to learn how to
        reference the Server Variables collection.

        <%= Clinton Gallagher
        NET csgallagher AT metromilwaukee. com
        URL http://www.metromilwaukee.com/clintongallagher/

        Comment

        • Kevin Spencer

          #5
          Re: When are cookies created?

          Hi Kevin,

          I believe you may be running into an issue with your format for your Cookie
          values. A little background is in order.

          Cookies are included in the header portion of an HTTP message, both Request
          and Response. An HTTP message is pure text. The headers are lines of text
          that appear before the body of the HTTP message, which in the case of a web
          site or web page, is generally a container for an HTML document (although it
          can also be a container for binary data such as images, etc). The text is
          parsed on both ends to build the Cookies objects on the server and client.

          There can be multiple cookies in an HTTP message, and each cookie may
          contain multiple attributes. The Cookie header consists of one of several
          different implementations , such as "set-cookie:", "cookie:", "Set-Cookie2:",
          or "Cookie2:", depending upon whether the cookies are coming from server or
          client, and what version is being used. This is followed by 0 or more
          comma-delimited cookies.

          Each cookie consists of 0 or more name=value attributes, delimited by
          semi-colons. Example:

          From the server:

          Set-Cookie2: Customer="WILE_ E_COYOTE"; Version="1"; Path="/acme"

          From the client:

          Cookie: $Version="1"; Customer="WILE_ E_COYOTE"; $Path="/acme"

          These are examples of Cookie headers with single cookies in them.

          As you have probably figured out, your cookie *content* follows a similar
          convention. This could be causing some problem in the interpretation of the
          cookie, which results in it being rejected by the parser.

          I would recommend using multiple cookies instead.

          For more information, see: http://rfc.dotsrc.org/rfc/rfc2965.html

          --
          HTH,

          Kevin Spencer
          Microsoft MVP
          Professional Chicken Salad Alchemist

          What You Seek Is What You Get.


          "Kevin Blount" <kevin.blount@g mail.comwrote in message
          news:1153523896 .038422.298800@ m79g2000cwm.goo glegroups.com.. .
          I've setup a method (C#) that I can call, passing it a cookie name,
          then a name-value pair. The idea is that as I can't append to a cookie,
          I read the cookie value, append by name=pair to the end and write it
          back... which works fine for adding a single name-value pair on a page.
          >
          The problem is, I want/need to add multiple name-values pairs, the
          number of which changing between pages (some might have 3, another 8).
          In my test scripts I've found a major problem when trying to add even 2
          pairs on a single page.
          >
          The problem is this:
          >
          - the first time I call my method, it checks the current cookie value,
          which is say "loggedin=t rue"
          - it then appendsthe name-value pair passed to the method ("name" and
          "kevin") as a new string, i.e. "loggedin=true& name=kevin"
          - I think write the new string as the value of the cookie and return to
          my aspx calling page
          >
          the second time I call the method, I check the current cookie value
          again (naturally), which I'd expect to be "loggedin=true& name=kevin",
          but in fact it's the original value of just "loggedin=true" . This means
          that when I add the second passed name-value pair (say, "gender" and
          "male") the final value of the cookie is "loggedin=true& gender=male".
          >
          I say 'final', cause if I check the value of the cookie on my calling
          page (i.e. without refreshing or going to another page), the value of
          the cookies is STILL the original one, not the one I did with my
          Response.Cookie s(...) or Response.Cookie s.Set(...) or any of the other
          properties I've tried.
          >
          So, back to my original question: when exactly do cookies get written
          to the browser? It seems to me that it's only when the current page is
          reloaded or moved away from. Can that really be the case??
          >
          Many thanks
          >

          Comment

          • clintonG

            #6
            Re: When are cookies created?

            Search the web to find a script that will output the collection of the
            ServerVariables collection. Find an application like IECookiesView or some
            other method that will help you read cookies during development if your
            using IE. Use Google to search the web and study. Quite frankly Firefox (FF)
            is the better browser and has better web development add-ins (especially for
            managing cookies).

            Do some study to learn about HTTP and how a web page is requested and how
            the response is sent back to the browser. Start with this article I just
            found for you [1] noting the best thing I can tell a layman who I hope is
            interested in becoming a competent web developer is to take words and
            terminology from newsgroup articles and learn how to search the web.

            <%= Clinton Gallagher
            NET csgallagher AT metromilwaukee. com
            URL http://www.metromilwaukee.com/clintongallagher/

            [1] http://www.perlfect.com/articles/http.shtml



            "Kevin Blount" <kevin.blount@g mail.comwrote in message
            news:1153555375 .341518.217900@ s13g2000cwa.goo glegroups.com.. .
            >I forgot to ask what "The cookie is passed in the response of the
            header." means in laymans terms.
            >
            Kevin
            >
            >clintonG wrote:
            The cookie is passed in the response of the header. You need to learn
            how to
            reference the Server Variables collection.
            >
            <%= Clinton Gallagher
            NET csgallagher AT metromilwaukee. com
            URL http://www.metromilwaukee.com/clintongallagher/
            >

            Comment

            Working...