Cookies. Simple Question. Thank You.

S

Shapper

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
 
D

David Young

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top