Array of cookies

  • Thread starter Thread starter Wanda
  • Start date Start date
W

Wanda

I want to store related data in an array of cookies, is there a way to
do it in aspnet?
I would like to see something like

Response.Cookies(key)(1).Value = "aaa"
Response.Cookies(key)(2).Value = "bbb"

If not, could you please suggest me some other method in details?

Thank in advance. Any help would be greatly appreciated.
Wanda
 
HttpCookie c = new HttpCookie("myCookie");
c.Values.Add("key1", "val1");
c.Values.Add("key2", "val2");
....
Response.Cookies.Add(c)

use the Values (instead of Value) property of the HttpCookie class.

Karl
 
I just couldn't get my cookie back, what have I done wrong?

'Getting the cookie by:
MyCookie = Request.Cookies("name of cookie")

'Setting the cookie:
myCookie = New HttpCookie("name of cookie")
MyCookie.Values.Add(key, "abc")
MyCookie.Expires = Now.AddYears(10)
Response.Cookies.Add(myCookie)

but it returns nothing.

Does this get remove when the session is ended(when the users close the
window)?

Please help!!! Any advice would be greatly appreciated.
Wanda
 
I just couldn't get my cookie back, what have I done wrong?

'Getting the cookie by:
MyCookie = Request.Cookies("name of cookie")

'Setting the cookie:
myCookie = New HttpCookie("name of cookie")
MyCookie.Values.Add(key, "abc")
MyCookie.Expires = Now.AddYears(10)
Response.Cookies.Add(myCookie)

but it returns nothing.

Does this get remove when the session is ended(when the users close the
window)?

Please help!!! Any advice would be greatly appreciated.
Wanda
 
Wanda,
Looking at your code I see nothing suspect...I was able to get it working on
my own computer....Note however that the cookie expiry is simply a
recommendation to browsers...there's no guarantee that they'll actually keep
the cookie around for any set period of time. I don't think this is what's
happening in this case forever...don't have any good answers for you..

Karl
 
any idea how I can add a cookie to an existing cookies list?
e.g. the "name of cookie" cookie that I have in the previous example!

I still have no idea why I can't get the cookies back once my session is
closed.
Thanks
Wanda
 
any idea how I can add a cookie to an existing cookies list?
e.g. the "name of cookie" cookie that I have in the previous example!

I still have no idea why I can't get the cookies back once my session is
closed.
Thanks
Wanda
 
Back
Top