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","ke***@m ydomain.com")
%>
....
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&emailaddress=ke***@my domain.com', 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>) 2 1365
I've discovered that what's happening isn't that the method is being
used to quickly, but rather the creation of the new cookie isn't being
commited between each call to the method.
In my testing I found that I can update the cookie in setCookie.aspx,
and then if I try to access that cookie in the same page, using
Request.Cookies, it will show the old, un-updated value.
This means that when I call the method for the second time, the cookie
value I am reading and appending to is the old one, not the new one.
The only time I see the new value of the cookie is when I either reload
the page, or go to another page, such as viewcookie.aspx.
Any clues why the cookies is not 'instantly' being written??
Kevin
Kevin Blount wrote:
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","ke***@m ydomain.com")
%>
...
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&emailaddress=ke***@my domain.com', 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>)
Hi Kevin,
Try buffering all changes to cookies until immediately before the request is completed.
using System.Collections.Generic;
/// <summary><see cref="Dictionary" /of string keys and values for buffering cookies until
the <see cref="Page" /is rendered, at which time the buffered cookies are written to the
<see cref="Response" /in the <see cref="Page.PreRender" /event.</summary>
private readonly void Dictionary<string, Dictionary<string, string>>
cookieBuffer = new Dictionary<string, Dictionary<string, string>>();
--
Dave Sexton
"Kevin Blount" <ke**********@gmail.comwrote in message news:11**********************@i42g2000cwa.googlegr oups.com...
I've discovered that what's happening isn't that the method is being
used to quickly, but rather the creation of the new cookie isn't being
commited between each call to the method.
In my testing I found that I can update the cookie in setCookie.aspx,
and then if I try to access that cookie in the same page, using
Request.Cookies, it will show the old, un-updated value.
This means that when I call the method for the second time, the cookie
value I am reading and appending to is the old one, not the new one.
The only time I see the new value of the cookie is when I either reload
the page, or go to another page, such as viewcookie.aspx.
Any clues why the cookies is not 'instantly' being written??
Kevin
Kevin Blount wrote:
>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","ke***@ mydomain.com") %> ...
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&emailaddress=ke***@m ydomain.com', 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>)
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lkrubner |
last post by:
I killed last night and a good chunk of today trying to figure out this
one particular attempt to get a class and initialize it. My code is
using a class method called getObject to include() a file...
|
by: Jazper |
last post by:
hi
i have this problem. i made a class deverted by CRootItem with
implementation of IDisposable-Interface. i made a test-funktion to test my
Dispose-Method.... but when set a breakpoint in my...
|
by: moondaddy |
last post by:
I have a website where cataloge pages are populated by calling a stored
procedure on sql server. I use the sql data adapter's fill method to call
this stored procedure and fill the dataset. about...
|
by: JohnR |
last post by:
From reading the documentation, this should be a relatively easy thing. I
have an arraylist of custom class instances which I want to search with
an"indexof" where I'm passing an instance if the...
|
by: Vincent |
last post by:
I have a hierarchical flex grid on an Access form and in the MouseMove
routine for the flex grid I am changing the color of the cells as the
mouse is moved over the cell. If I move the mouse...
|
by: Allan Ebdrup |
last post by:
I'm writing some code where I have have a class that implements 4 methods
(class A)
I only want to call these methods from the base class if they have been
overridden in a sub class (Class B) I...
|
by: Agustin Villena |
last post by:
Hi!
is there anyway to show the class of a method in an exception's
traceback?
For example, the next code
class Some(object):
def foo(self,x):
raise Exception(x)
|
by: Anders Borum |
last post by:
Hi!
While implementing a property manager (that supports key / value pairs), I
was wondering how to constrain T to a struct or string type. Basically, I
guess what I'm looking for is the common...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |