K
Kevin Blount
I have a situation where I think I'm calling a method too quickly, but
I'm not sure a) how to prove that theory and b) slow it down if I'm
right. Here's the code:
CODEFILE.ASPX.CS
public void updateCookie(string cookieName, string cookiePairName,
string cookiePairValue) {
if (Request.Cookies[cookieName] != null) {
string currentCookie = Request.Cookies[cookieName].Value;
currentCookie += "&" + cookiePairName + "=" + cookiePairValue;
Response.Cookies[cookieName].Value = currentCookie;
}
else
{
Response.Cookies[cookieName][cookiePairName] = cookiePairValue;
}
Response.Cookies[cookieName].Expires = DateTime.Now.AddDays(30);
}
SETCOOKIE1.ASPX
....
<%
updateCookie("Communities","LoggedIn","true");
updateCookie("Communities","member_id","120");
%>
....
SETCOOKIE2.ASPX
....
<%
updateCookie("Communities","banner","1");
updateCookie("Communities","emailaddress","(e-mail address removed)")
%>
....
VIEWCOOKIE.ASPX
....
Response.Write(Request.Cookies["Communities"].Value);
....
The issue is this:
- initially I delete all cookies from I.E. and view 'viewcookie.aspx'
to confirm that no cookie value is displayed.
- Next I view 'setcookie1.aspx', then go back to 'viewcookie.aspx',
refresh and I see something like 'LoggedIn=true&member_id=120', as I'd
expect.
- I then view 'setcookie2.aspx', go back to 'viewcookie.aspx' and
refresh...
this time I see
'LoggedIn=true&member_id=120&[email protected]', whereas
I would expect to see '&banner=1' before '&emailaddress...', i.e. 4
name-value pairs set by the two aspx files, rather than just 3 pairs
if I comment out the 'updateCookie' lines one at a time in
setcookie2.aspx, they both work individually, but when they are both
uncommented, only one of the two calls to updateCookie actually work.
the same is true if I run setcookie2.aspx before I run
setcookie1.aspx.. i.e. both values from setcookie2.aspx are in the
cookie, but only one of those from setcookie1.aspx gets entered.
also, if I go back to the setcookie file where both entries were added
and run it again while the cookie exists, only one of the two
previously working entries is appended
Am I calling the method too quickly? can I slow it down? Is there a
better way to do the cookie part that won't cause this??
any help would be very appreciated (let me know if my explaination is
too irratic <g>)
I'm not sure a) how to prove that theory and b) slow it down if I'm
right. Here's the code:
CODEFILE.ASPX.CS
public void updateCookie(string cookieName, string cookiePairName,
string cookiePairValue) {
if (Request.Cookies[cookieName] != null) {
string currentCookie = Request.Cookies[cookieName].Value;
currentCookie += "&" + cookiePairName + "=" + cookiePairValue;
Response.Cookies[cookieName].Value = currentCookie;
}
else
{
Response.Cookies[cookieName][cookiePairName] = cookiePairValue;
}
Response.Cookies[cookieName].Expires = DateTime.Now.AddDays(30);
}
SETCOOKIE1.ASPX
....
<%
updateCookie("Communities","LoggedIn","true");
updateCookie("Communities","member_id","120");
%>
....
SETCOOKIE2.ASPX
....
<%
updateCookie("Communities","banner","1");
updateCookie("Communities","emailaddress","(e-mail address removed)")
%>
....
VIEWCOOKIE.ASPX
....
Response.Write(Request.Cookies["Communities"].Value);
....
The issue is this:
- initially I delete all cookies from I.E. and view 'viewcookie.aspx'
to confirm that no cookie value is displayed.
- Next I view 'setcookie1.aspx', then go back to 'viewcookie.aspx',
refresh and I see something like 'LoggedIn=true&member_id=120', as I'd
expect.
- I then view 'setcookie2.aspx', go back to 'viewcookie.aspx' and
refresh...
this time I see
'LoggedIn=true&member_id=120&[email protected]', whereas
I would expect to see '&banner=1' before '&emailaddress...', i.e. 4
name-value pairs set by the two aspx files, rather than just 3 pairs
if I comment out the 'updateCookie' lines one at a time in
setcookie2.aspx, they both work individually, but when they are both
uncommented, only one of the two calls to updateCookie actually work.
the same is true if I run setcookie2.aspx before I run
setcookie1.aspx.. i.e. both values from setcookie2.aspx are in the
cookie, but only one of those from setcookie1.aspx gets entered.
also, if I go back to the setcookie file where both entries were added
and run it again while the cookie exists, only one of the two
previously working entries is appended
Am I calling the method too quickly? can I slow it down? Is there a
better way to do the cookie part that won't cause this??
any help would be very appreciated (let me know if my explaination is
too irratic <g>)