473,785 Members | 2,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application Object Stores the Same Key Multiple Times

Hi Everyone,

I'm new to ASP.NET so maybe this is easy. I'm using ASP.NET 2.0.

I'm finding that the Application object (the HttpApplication State
object) is allowing me to add the same key multiple times. The easiest
way to describe the problem is to just show you.

In my Page_Load() I have this code:

Application.Add ("Fred", "Pebbles");
Application.Add ("Fred", "Wilma");
Application.Add ("Fred", "Dino");

Application.Set ("Fred", "Barney");

foreach (string key in Application.All Keys) {
object val = Application.Get (key);
Trace.Write("Fr ed's value: " + val.ToString()) ;
}

for (int i = 0; i < Application.Cou nt; ++i) {
object val = Application.Get (i);
Trace.Write("va l " + i + ": " + val);
}
Notice I am using the same key -- "Fred" -- multiple times.

When I look at the Trace output here's what I see:

Fred's value: Barney
Fred's value: Barney
Fred's value: Barney
val 0: Barney
val 1: Wilma
val 2: Dino

I really don't know what to make of this except that it's totally
unexpected and inconsistent with a regular hashtable's behavior. I've
read the Microsoft documentation and I didn't see any mention of this
kind of behavior. My understanding was that Application should behave
like a hashtable.

Can anyone comment on this behavior? Does it seem right?

Thanks.
--
Alan Foxmore
May 25 '06 #1
2 1777
thats by design. if you add an exisiting key, it replaces the old value.

-- bruce (sqlwork.com)
"Alan Foxmore" <AF******@yahoo .com> wrote in message
news:%2******** **********@TK2M SFTNGP03.phx.gb l...
Hi Everyone,

I'm new to ASP.NET so maybe this is easy. I'm using ASP.NET 2.0.

I'm finding that the Application object (the HttpApplication State object)
is allowing me to add the same key multiple times. The easiest way to
describe the problem is to just show you.

In my Page_Load() I have this code:

Application.Add ("Fred", "Pebbles");
Application.Add ("Fred", "Wilma");
Application.Add ("Fred", "Dino");

Application.Set ("Fred", "Barney");

foreach (string key in Application.All Keys) {
object val = Application.Get (key);
Trace.Write("Fr ed's value: " + val.ToString()) ;
}

for (int i = 0; i < Application.Cou nt; ++i) {
object val = Application.Get (i);
Trace.Write("va l " + i + ": " + val);
}
Notice I am using the same key -- "Fred" -- multiple times.

When I look at the Trace output here's what I see:

Fred's value: Barney
Fred's value: Barney
Fred's value: Barney
val 0: Barney
val 1: Wilma
val 2: Dino

I really don't know what to make of this except that it's totally
unexpected and inconsistent with a regular hashtable's behavior. I've read
the Microsoft documentation and I didn't see any mention of this kind of
behavior. My understanding was that Application should behave like a
hashtable.

Can anyone comment on this behavior? Does it seem right?

Thanks.
--
Alan Foxmore

May 25 '06 #2


thats by design. if you add an exisiting key, it replaces the old
value.

-- bruce (sqlwork.com)

Hi Bruce,

By design? Adding an existing key is NOT replacing the old value. Did
you even look at the example I gave?

I am still able to access 'Wilma' and 'Dino'. They are *not* replaced.
If I remove the call to "Application.Se t("Fred", "Barney");" then
"Application.Ge t("Fred")" returns "Pebbles". According to what you say
(and what I would expect), it should return 'Dino'.

Take a look at the calls to Application.Add () and Application.Set () and
then look at the results.



"Alan Foxmore" <AF******@yahoo .com> wrote in message
news:%2******** **********@TK2M SFTNGP03.phx.gb l...
Hi Everyone,

I'm new to ASP.NET so maybe this is easy. I'm using ASP.NET 2.0.

I'm finding that the Application object (the HttpApplication State
object) is allowing me to add the same key multiple times. The
easiest way to describe the problem is to just show you.

In my Page_Load() I have this code:

Application.Add ("Fred", "Pebbles");
Application.Add ("Fred", "Wilma");
Application.Add ("Fred", "Dino");

Application.Set ("Fred", "Barney");

foreach (string key in Application.All Keys) {
object val = Application.Get (key);
Trace.Write("Fr ed's value: " + val.ToString()) ;
}

for (int i = 0; i < Application.Cou nt; ++i) {
object val = Application.Get (i);
Trace.Write("va l " + i + ": " + val);
}
Notice I am using the same key -- "Fred" -- multiple times.

When I look at the Trace output here's what I see:

Fred's value: Barney
Fred's value: Barney
Fred's value: Barney
val 0: Barney
val 1: Wilma
val 2: Dino

I really don't know what to make of this except that it's totally
unexpected and inconsistent with a regular hashtable's behavior.
I've read the Microsoft documentation and I didn't see any mention
of this kind of behavior. My understanding was that Application
should behave like a hashtable.

Can anyone comment on this behavior? Does it seem right?

Thanks.
--
Alan Foxmore


May 25 '06 #3

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

Similar topics

2
10699
by: Sri | last post by:
I am writing an asp.net applicaition using VB coding. In a function, I am opening an excel file with the following code, Dim objExcel As Object Dim objWorkBook As Object objExcel = CreateObject("Excel.Application") objWorkBook = objExcel.Workbooks.Open(targetfilename) * targetfilename is a variable that stores the excel file name and path. In the error handler,
9
23084
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated to a pool. If I assign only one application to a applicaton pool and have multiple worker processes assigned to that pool. Will my application be processed by many worker processes?
10
1820
by: Steve Taylor | last post by:
I am having trouble understanding the ASP.NET application boundaries. Here's my setup: 1. Win2003 Server with IIS 6 and an application defined at the root "SalesNow" (www.salesnow.com). 2. A Default.aspx at the root which redirects the user to "Pages/Main.aspx" using javascript window.location. 3. On the Pages/Main.aspx page a HyperLink control which I add a javascript onclick event which does the following: - NewLeadWin =...
9
2778
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
20
2723
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in contrast to one of them always being 'modal' (e.g., if you are moving over a picture the 'Info' form will update the (x,y) screen location in realtime even if not the selected form. Also note that this example implies the various forms can communicate...
22
3247
by: roadrunner | last post by:
Hi, Our website has recently been experiencing some problems under load. We have pinpointed a particular function which slows dramatically when we have these problems. Normally it should execute in under a second but it rises to about one minute under duress. The code is fairly straight forward with no calls to databases or any other servers. The only dubious thing I can see is that it retrieves several arrays from the Application...
0
2215
by: =?Utf-8?B?SkhhbGV5?= | last post by:
Our system is: IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram Windows Server 2003 SP2 IIS 6.0 SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server) Windows Server 2003 SP2 SQL Server 2000 We are having some problems with a website we are developing, and had some
0
985
by: Ciri | last post by:
Hi all, is it possible to have different user.config file for different instances of an application running on the same machine? I've seen that a different folder is created under Documents and Settings/User_name/Local setting/Application Data each time I run the application from a different path. Inside each of these folders there's a user.config file that stores a different set of settings. This way, the result is that I have a...
4
4531
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst child apps of an IIS application and can be used by multiple users during the application life cycle and for multiple page loads for the same or different page under a root application. What I don't understand and need to know is whether that...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9952
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.