Reputation: 28316
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?
Upvotes: 2
Views: 277
Reputation: 42003
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!
Upvotes: 1