joe_pool_is
Contributor
Someone please show me how to *create* subitems (or subkeys) for my cookies. I have found code out there for doing this in VB.NET, but I can not seem to get it to work in C#. Here is what I have:
Code:
void Page_Load(Object Sender, EventArgs e) {
HttpCookie cookie = Request.Cookies["userCookie"];
if (cookie == null) {
cookie = new HttpCookie("userInfo");
cookie.HasKeys = true; // this bombs: HasKeys is read only
cookie.Value["userInfo"]["userName"] = "jdoe"; // this bombs. Why?
cookie.Value["realName"] = "John Doe"; // this bombs, too. Why?
cookie.Value["lastVisit"] = DateTime.Now.ToString; // can't get this far
cookie.Expires = DateTime.Now.AddDays(365);
cookie.Path = Server.MapPath("/");
Response.Cookies.Add(cookie);
}
}