views:

24

answers:

1

In my web.config, appSettings section, I have several keys. What is the preferred way to handle in code any keys that are missing? For example, a key name is changed due to a typo. I know I can use various methods to test if the values of said keys exist but what about the key itself?

A: 

I found that ConfigurationManager.AppSettings["key"] (requires System.Configuration assembly reference) will return null if the key is not found.

In that case, I throw an instance of my own MyAppConfigurationException with something helpful: like Couldn't open repository, configuration key RepositoryAccess.Customer was not found.

Hope that helps!

Kieren Johnstone