Hello,
The following code creates 100 cookies and then enumerates through them via postbacks.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < 100; i++)
{
HttpCookie cookie = new HttpCookie("cookie num." + i.ToString());
cookie["Cookie"] = i.ToString() + "th cookie, anyone?";
cookie.Expires = DateTime.Now.AddMonths(1);
Response.Cookies.Add(cookie);
}
int i1 = 0;
Session["i"] = i1;
}
if (IsPostBack)
{
int i = (int)Session["i"];
HttpCookie cookie= Request.Cookies["Cookie num." + i.ToString()];
Label1.Text = cookie["Cookie"];
Session["i"] = ++i;
}
}
Q1 - But when using Firefox, instead of being able to enumerate through all of 100 cookies, app only manages to go through first 20 (max 40) cookies before reporting Object reference not set to an instance of an object exeception:
Q2 - when I request this page via IE, then I will always get Object reference not set to an instance of an object exception ( BTW – I checked and IE did manage to store all 100 cookies into a single file ) on the first postback.
thanx
EDIT:
But the following link applies to IE, while it is Firefox that doesn't save all cookies. And with IE, code is not able to enumerate through none of the cookies. SO the above answer would be valid if I was at least able to enumerate through first 20 cookies ( in IE ), which I'm not
2. EDIT:
The spec makes no guarantee which cookies a browser must keep when it runs out of storage, so browsers are free to behave how they like, and you should expect different behaviours. What's more, in your example, all the cookies are set in headers of a single response. HTTP headers are not ordered, so there's no guarantee they will be processed in any particular order in the first place.
What exactly do you mean by "processed"?
thanx for helping me out