A
Alan Foxmore
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.
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.