K
Kevin Blount
I've setup a method (C#) that I can call, passing it a cookie name,
then a name-value pair. The idea is that as I can't append to a cookie,
I read the cookie value, append by name=pair to the end and write it
back... which works fine for adding a single name-value pair on a page.
The problem is, I want/need to add multiple name-values pairs, the
number of which changing between pages (some might have 3, another 8).
In my test scripts I've found a major problem when trying to add even 2
pairs on a single page.
The problem is this:
- the first time I call my method, it checks the current cookie value,
which is say "loggedin=true"
- it then appendsthe name-value pair passed to the method ("name" and
"kevin") as a new string, i.e. "loggedin=true&name=kevin"
- I think write the new string as the value of the cookie and return to
my aspx calling page
the second time I call the method, I check the current cookie value
again (naturally), which I'd expect to be "loggedin=true&name=kevin",
but in fact it's the original value of just "loggedin=true". This means
that when I add the second passed name-value pair (say, "gender" and
"male") the final value of the cookie is "loggedin=true&gender=male".
I say 'final', cause if I check the value of the cookie on my calling
page (i.e. without refreshing or going to another page), the value of
the cookies is STILL the original one, not the one I did with my
Response.Cookies(...) or Response.Cookies.Set(...) or any of the other
properties I've tried.
So, back to my original question: when exactly do cookies get written
to the browser? It seems to me that it's only when the current page is
reloaded or moved away from. Can that really be the case??
Many thanks
then a name-value pair. The idea is that as I can't append to a cookie,
I read the cookie value, append by name=pair to the end and write it
back... which works fine for adding a single name-value pair on a page.
The problem is, I want/need to add multiple name-values pairs, the
number of which changing between pages (some might have 3, another 8).
In my test scripts I've found a major problem when trying to add even 2
pairs on a single page.
The problem is this:
- the first time I call my method, it checks the current cookie value,
which is say "loggedin=true"
- it then appendsthe name-value pair passed to the method ("name" and
"kevin") as a new string, i.e. "loggedin=true&name=kevin"
- I think write the new string as the value of the cookie and return to
my aspx calling page
the second time I call the method, I check the current cookie value
again (naturally), which I'd expect to be "loggedin=true&name=kevin",
but in fact it's the original value of just "loggedin=true". This means
that when I add the second passed name-value pair (say, "gender" and
"male") the final value of the cookie is "loggedin=true&gender=male".
I say 'final', cause if I check the value of the cookie on my calling
page (i.e. without refreshing or going to another page), the value of
the cookies is STILL the original one, not the one I did with my
Response.Cookies(...) or Response.Cookies.Set(...) or any of the other
properties I've tried.
So, back to my original question: when exactly do cookies get written
to the browser? It seems to me that it's only when the current page is
reloaded or moved away from. Can that really be the case??
Many thanks