Cookie Over Write

Discussion in 'ASP General' started by Scott, Jan 4, 2006.

  1. Scott

    Scott Guest

    if i create a cookie named myCompany and store several values like userLast
    and userFirst and then later want to add a new name-pair such as
    userPreference1, can i append the new name-pair without re-writing the
    userLast and userFirst name-pairs?

    In other words, does a new name-pair to the same cookie over write other
    existing keys?

    CODE:
    Response.Cookies("myCompany")("userLast") = Session("userLast")
    Response.Cookies("myCompany")("userFirst") = Session("userFirst")

    CODE 2:
    Response.Cookies("myCompany")("userPreference1") =
    Session("userPreference1")
    Scott, Jan 4, 2006
    #1
    1. Advertising

  2. I am pretty sure every time you change any Key in the cookie you have to
    rewrite them all or you will lose the key you don't set.
    It is just the way they work.

    "Scott" <> wrote in message
    news:...
    > if i create a cookie named myCompany and store several values like
    > userLast and userFirst and then later want to add a new name-pair such as
    > userPreference1, can i append the new name-pair without re-writing the
    > userLast and userFirst name-pairs?
    >
    > In other words, does a new name-pair to the same cookie over write other
    > existing keys?
    >
    > CODE:
    > Response.Cookies("myCompany")("userLast") = Session("userLast")
    > Response.Cookies("myCompany")("userFirst") = Session("userFirst")
    >
    > CODE 2:
    > Response.Cookies("myCompany")("userPreference1") =
    > Session("userPreference1")
    >
    Kyle Peterson, Jan 4, 2006
    #2
    1. Advertising

  3. Scott

    Evertjan. Guest

    Kyle Peterson wrote on 04 jan 2006 in
    microsoft.public.inetserver.asp.general:
    > "Scott" <> wrote in message
    > news:...
    >> if i create a cookie named myCompany and store several values like
    >> userLast and userFirst and then later want to add a new name-pair
    >> such as userPreference1, can i append the new name-pair without
    >> re-writing the userLast and userFirst name-pairs?
    >>
    >> In other words, does a new name-pair to the same cookie over write
    >> other existing keys?
    >>
    >> CODE:
    >> Response.Cookies("myCompany")("userLast") = Session("userLast")
    >> Response.Cookies("myCompany")("userFirst") = Session("userFirst")
    >>
    >> CODE 2:
    >> Response.Cookies("myCompany")("userPreference1") =
    >> Session("userPreference1")
    >>

    > I am pretty sure every time you change any Key in the cookie you have
    > to rewrite them all or you will lose the key you don't set.
    > It is just the way they work.


    Not true.
    But why ask?
    Such things are so easy to test:

    ========== test1.asp ==========

    <%
    Response.Cookies("myCompany")("1") = "x1"
    Response.Cookies("myCompany")("2") = "x2"
    %>
    <a href ='test2.asp'>go to test2.asp</a>

    ========== test2.asp ==========

    <%
    Response.Cookies("myCompany")("3") = "x3"
    %>

    <br><%=Request.Cookies("myCompany")("1")%>
    <br><%=Request.Cookies("myCompany")("2")%>
    <br><%=Request.Cookies("myCompany")("3")%>

    ========= test2.asp shows:

    x1
    x2
    x3


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 4, 2006
    #3
  4. Scott

    scott Guest

    thanks.

    "Evertjan." <> wrote in message
    news:Xns97416493D474eejj99@194.109.133.242...
    > Kyle Peterson wrote on 04 jan 2006 in
    > microsoft.public.inetserver.asp.general:
    >> "Scott" <> wrote in message
    >> news:...
    >>> if i create a cookie named myCompany and store several values like
    >>> userLast and userFirst and then later want to add a new name-pair
    >>> such as userPreference1, can i append the new name-pair without
    >>> re-writing the userLast and userFirst name-pairs?
    >>>
    >>> In other words, does a new name-pair to the same cookie over write
    >>> other existing keys?
    >>>
    >>> CODE:
    >>> Response.Cookies("myCompany")("userLast") = Session("userLast")
    >>> Response.Cookies("myCompany")("userFirst") = Session("userFirst")
    >>>
    >>> CODE 2:
    >>> Response.Cookies("myCompany")("userPreference1") =
    >>> Session("userPreference1")
    >>>

    >> I am pretty sure every time you change any Key in the cookie you have
    >> to rewrite them all or you will lose the key you don't set.
    >> It is just the way they work.

    >
    > Not true.
    > But why ask?
    > Such things are so easy to test:
    >
    > ========== test1.asp ==========
    >
    > <%
    > Response.Cookies("myCompany")("1") = "x1"
    > Response.Cookies("myCompany")("2") = "x2"
    > %>
    > <a href ='test2.asp'>go to test2.asp</a>
    >
    > ========== test2.asp ==========
    >
    > <%
    > Response.Cookies("myCompany")("3") = "x3"
    > %>
    >
    > <br><%=Request.Cookies("myCompany")("1")%>
    > <br><%=Request.Cookies("myCompany")("2")%>
    > <br><%=Request.Cookies("myCompany")("3")%>
    >
    > ========= test2.asp shows:
    >
    > x1
    > x2
    > x3
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
    scott, Jan 4, 2006
    #4
  5. Evertjan is correct. My Bad.
    Not sure why I thought that but I could swear I encountered that or read
    that it did that in the past.


    "Evertjan." <> wrote in message
    news:Xns97416493D474eejj99@194.109.133.242...
    > Kyle Peterson wrote on 04 jan 2006 in
    > microsoft.public.inetserver.asp.general:
    >> "Scott" <> wrote in message
    >> news:...
    >>> if i create a cookie named myCompany and store several values like
    >>> userLast and userFirst and then later want to add a new name-pair
    >>> such as userPreference1, can i append the new name-pair without
    >>> re-writing the userLast and userFirst name-pairs?
    >>>
    >>> In other words, does a new name-pair to the same cookie over write
    >>> other existing keys?
    >>>
    >>> CODE:
    >>> Response.Cookies("myCompany")("userLast") = Session("userLast")
    >>> Response.Cookies("myCompany")("userFirst") = Session("userFirst")
    >>>
    >>> CODE 2:
    >>> Response.Cookies("myCompany")("userPreference1") =
    >>> Session("userPreference1")
    >>>

    >> I am pretty sure every time you change any Key in the cookie you have
    >> to rewrite them all or you will lose the key you don't set.
    >> It is just the way they work.

    >
    > Not true.
    > But why ask?
    > Such things are so easy to test:
    >
    > ========== test1.asp ==========
    >
    > <%
    > Response.Cookies("myCompany")("1") = "x1"
    > Response.Cookies("myCompany")("2") = "x2"
    > %>
    > <a href ='test2.asp'>go to test2.asp</a>
    >
    > ========== test2.asp ==========
    >
    > <%
    > Response.Cookies("myCompany")("3") = "x3"
    > %>
    >
    > <br><%=Request.Cookies("myCompany")("1")%>
    > <br><%=Request.Cookies("myCompany")("2")%>
    > <br><%=Request.Cookies("myCompany")("3")%>
    >
    > ========= test2.asp shows:
    >
    > x1
    > x2
    > x3
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
    Kyle Peterson, Jan 4, 2006
    #5
  6. Evertjan. wrote:
    >> I am pretty sure every time you change any Key in the cookie
    >> you have to rewrite them all or you will lose the key you
    >> don't set. It is just the way they work.

    >
    > Not true.


    More like "partially true". If you write them from the client side, they all
    get overwritten.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, Jan 4, 2006
    #6
  7. Scott

    Evertjan. Guest

    Dave Anderson wrote on 04 jan 2006 in
    microsoft.public.inetserver.asp.general:

    > Evertjan. wrote:
    >>> I am pretty sure every time you change any Key in the cookie
    >>> you have to rewrite them all or you will lose the key you
    >>> don't set. It is just the way they work.

    >>
    >> Not true.

    >
    > More like "partially true". If you write them from the client side,
    > they all get overwritten.


    Why would you, if you have ASP?

    ;-}

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 4, 2006
    #7
  8. Evertjan. wrote:
    >> More like "partially true". If you write them from the client
    >> side, they all get overwritten.

    >
    > Why would you, if you have ASP?


    Indeed, ASP renders moot any and all client-side scripting. Anything that
    can be done with DHTML can also be done with one or more round-trips.

    Or not.


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, Jan 4, 2006
    #8
  9. Scott

    Evertjan. Guest

    Dave Anderson wrote on 04 jan 2006 in
    microsoft.public.inetserver.asp.general:

    > Evertjan. wrote:
    >>> More like "partially true". If you write them from the client
    >>> side, they all get overwritten.

    >>
    >> Why would you, if you have ASP?

    >
    > Indeed, ASP renders moot any and all client-side scripting. Anything
    > that can be done with DHTML can also be done with one or more
    > round-trips.
    >
    > Or not.


    Without your "round trip",
    there is no reason for manipulating a cookie.

    And I prefer the clientside code independence of ASP.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 4, 2006
    #9
  10. Evertjan. wrote:
    >> Indeed, ASP renders moot any and all client-side scripting. Anything
    >> that can be done with DHTML can also be done with one or more
    >> round-trips.
    >>
    >> Or not.

    >
    > Without your "round trip",
    > there is no reason for manipulating a cookie.


    Without a further request, perhaps, but cookies can be useful for a host of
    reasons (like state memory), and I see no reason why a round-trip should be
    mandated for simply setting a cookie.


    > And I prefer the clientside code independence of ASP.


    As do I. But like every tool in the bag, client-side scripting has its uses.
    And occasionally it is appropriate for writing cookies.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, Jan 5, 2006
    #10
  11. Scott

    Evertjan. Guest

    Dave Anderson wrote on 05 jan 2006 in
    microsoft.public.inetserver.asp.general:

    >> Without your "round trip",
    >> there is no reason for manipulating a cookie.

    >
    > Without a further request, perhaps, but cookies can be useful for a
    > host of reasons (like state memory), and I see no reason why a
    > round-trip should be mandated for simply setting a cookie.
    >


    That is not necessary as the "round trip" can wait till necessary anyway.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 5, 2006
    #11
  12. Evertjan. wrote:
    >> Without a further request, perhaps, but cookies can be useful for a
    >> host of reasons (like state memory), and I see no reason why a
    >> round-trip should be mandated for simply setting a cookie.

    >
    > That is not necessary as the "round trip" can wait till necessary
    > anyway.


    You mean setting the cookie? That response assumes the round-trip is the
    next destination for the browser. What if the user just wants to do
    something else with the browser and then return to your page later?
    Opportunity lost.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, Jan 5, 2006
    #12
  13. Scott

    Evertjan. Guest

    Dave Anderson wrote on 05 jan 2006 in
    microsoft.public.inetserver.asp.general:

    > Evertjan. wrote:
    >>> Without a further request, perhaps, but cookies can be useful for a
    >>> host of reasons (like state memory), and I see no reason why a
    >>> round-trip should be mandated for simply setting a cookie.

    >>
    >> That is not necessary as the "round trip" can wait till necessary
    >> anyway.

    >
    > You mean setting the cookie? That response assumes the round-trip is the
    > next destination for the browser. What if the user just wants to do
    > something else with the browser and then return to your page later?
    > Opportunity lost.


    True.

    I still think in a aspable environment, one should not demean oneself
    to a clientside construct. Usually there is a way around that.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jan 5, 2006
    #13
  14. Evertjan. wrote:
    > I still think in a aspable environment, one should not demean
    > oneself to a clientside construct. Usually there is a way
    > around that.


    I don't quite see it that way. I think the server-side approach is better,
    most of the time. But I am not fond of ironclad rules -- those that use
    words like ALWAYS or NEVER. Here is one I NEVER break: ALWAYS assume the
    client can manipulate any part of the request.

    With that in mind, I generally treat client-side scripting as a tool to make
    the experience more convenient for the user. If the OP had that purpose in
    mind and chose to tweak some cookies on the client-side, and those cookies
    have keys, then he must dispose of each key-value pair, not just the one
    being changed. Your opinion does not change that fact.



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, Jan 5, 2006
    #14
    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. Ben
    Replies:
    3
    Views:
    5,797
    Steven Cheng[MSFT]
    Jun 3, 2004
  2. Shapper

    Cookie and Session Cookie Questions.

    Shapper, Apr 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    554
  3. =?Utf-8?B?UGF1bA==?=

    Cookie Question (IP as domain and cookie file location)

    =?Utf-8?B?UGF1bA==?=, Jan 10, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    2,463
    Bruce Barker
    Jan 10, 2006
  4. ad
    Replies:
    2
    Views:
    7,466
    Kevin Spencer
    Jan 27, 2006
  5. =?Utf-8?B?TnVubw==?=

    Convert a PHP cookie to an ASP.NET cookie

    =?Utf-8?B?TnVubw==?=, Jan 31, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    430
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jan 31, 2006
Loading...

Share This Page