473,386 Members | 1,720 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,386 software developers and data experts.

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 HttpApplicationState
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.AllKeys) {
object val = Application.Get(key);
Trace.Write("Fred's value: " + val.ToString());
}

for (int i = 0; i < Application.Count; ++i) {
object val = Application.Get(i);
Trace.Write("val " + 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 1759
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******************@TK2MSFTNGP03.phx.gbl...
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 HttpApplicationState 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.AllKeys) {
object val = Application.Get(key);
Trace.Write("Fred's value: " + val.ToString());
}

for (int i = 0; i < Application.Count; ++i) {
object val = Application.Get(i);
Trace.Write("val " + 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.Set("Fred", "Barney");" then
"Application.Get("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******************@TK2MSFTNGP03.phx.gbl...
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 HttpApplicationState
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.AllKeys) {
object val = Application.Get(key);
Trace.Write("Fred's value: " + val.ToString());
}

for (int i = 0; i < Application.Count; ++i) {
object val = Application.Get(i);
Trace.Write("val " + 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
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 =...
9
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...
10
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...
9
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...
20
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...
22
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...
0
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...
0
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 ...
4
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.