Jeffrey Palermo (.com)

Sponsors

The Lounge

Wicked Cool Jobs

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
ASP.NET configuration gotcha - level 200

For people starting out with ASP.NET, the appSettings node in the web.config file will be all that is necessary for storing configuration items, but when you start creating your own config section handlers and strongly-typing your configuration items, you may run into a small snag that may cost you 1/2 a day to track down.

Configuration section names (since they are xml) are case sensitive.  Xml is case sensitive.

 

I have a section:

<configSections>

<section name="SiteMap" type="WebTestHarness.SiteMapConfig, WebTestHarness" />

</configSections>

but if I call:

ConfigurationSettings.GetConfig("siteMap");

I get mysterious errors elsewhere in my code.  My config section didn't get loaded.  It turns out that the section "siteMap" wasn't found.  "SiteMap" is the correct name.   Of course, I expected the .GetConfig() method to throw an exception if the section wasn't found, but it doesn't.  It just returns nothing and lets my code keep going.

 

Now, armed with this knowledge, I will just check the return value of the method to determine if the GetConfig was successful.


Posted Tue, Nov 30 2004 9:36 AM by Jeffrey Palermo

[Advertisement]

Comments

Dave wrote re: ASP.NET configuration gotcha - level 200
on Tue, Nov 30 2004 5:33 AM
Yep, you're right. Gotta always remember that config files are in XML which is case-sensitive. Has happened to me more than enough to count.
NoName wrote re: ASP.NET configuration gotcha - level 200
on Tue, Nov 30 2004 5:57 AM
Use C# it will give an error
Jeffrey Palermo wrote re: ASP.NET configuration gotcha - level 200
on Tue, Nov 30 2004 6:36 AM
I do use C#. The call to GetConfig() won't generate an exception.
Devlicio.us