473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

method being called to quickly?

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>)

Jul 21 '06 #1
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>)
Jul 21 '06 #2
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>)

Jul 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
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...
24
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...
5
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...
18
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...
0
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...
8
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...
21
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)
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.