Cookies. Simple Question. Thank You.

Discussion in 'ASP .Net' started by Shapper, Apr 29, 2005.

  1. Shapper

    Shapper Guest

    Hello,

    I need to know how to do 2 things:
    1. CREATE a NEW cookie with 2 values: "password" and "user".
    2. APPEND 2 new values to an ALLREADY EXISTING cookie.

    I created a code which is working:
    Dim cookie As HttpCookie = New HttpCookie("MyCookie")
    cookie.Values.Add("culture", "pt-PT")
    cookie.Expires = #01/01/2010#
    Response.Cookies.Add(cookie)

    I don't understand what code changes should I implement from (1) to (2).

    Can someone help me?

    Thank You,
    Miguel
     
    Shapper, Apr 29, 2005
    #1
    1. Advertising

  2. Shapper

    David Young Guest

    1.) Create Cookie with 2 values:

    HttpCookie cookie = new HttpCookie("myCookie");
    cookie["userid"] = "myid";
    cookie["password"] = "pwd";
    Request.Cookies.Add(cookie);

    *Note. Storing a password in a cookie is generally not a good idea.
    However, there may be times when this does need to be done. If you need to
    strore the users password in a cookie, then you should encrypt (hash) the
    password before storing it in the cookie or encrypt the entire cookie. Just
    a suggestion :) If you need help with the encryption aspect, shoot me an
    email.

    2) Add values to an existing cookie

    HttpCookie cookie = Request.Cookies["myCookie"];
    cookie["newKey"] = "newValue";
    Request.Cookies.Add(cookie);


    Dave
    dmy75252[removethis]@yahoo.com


    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
    news:...
    > Hello,
    >
    > I need to know how to do 2 things:
    > 1. CREATE a NEW cookie with 2 values: "password" and "user".
    > 2. APPEND 2 new values to an ALLREADY EXISTING cookie.
    >
    > I created a code which is working:
    > Dim cookie As HttpCookie = New HttpCookie("MyCookie")
    > cookie.Values.Add("culture", "pt-PT")
    > cookie.Expires = #01/01/2010#
    > Response.Cookies.Add(cookie)
    >
    > I don't understand what code changes should I implement from (1) to (2).
    >
    > Can someone help me?
    >
    > Thank You,
    > Miguel
    >
    >
     
    David Young, Apr 29, 2005
    #2
    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. Miguel Dias Moura
    Replies:
    1
    Views:
    422
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 1, 2004
  2. Miguel Dias Moura
    Replies:
    1
    Views:
    438
    Lars Netzel
    Jun 18, 2004
  3. Miguel Dias Moura
    Replies:
    2
    Views:
    370
    Martin
    Jun 22, 2004
  4. Shawn
    Replies:
    8
    Views:
    406
    Shawn
    Sep 21, 2006
  5. _Who
    Replies:
    7
    Views:
    2,772
Loading...

Share This Page