Reputation: 193
In web.config
, why can't we have duplicate connection strings and handlers but on the other hand, we can have duplicates <appSettings>
child elements with the same key name at the same level or down the inheritance hierarchy?
Upvotes: 1
Views: 1455
Reputation: 17485
I don't this will complete answer to your question or not but I have some information that I would like to share.
If you look
ConfigurationManager.AppSettings
then it is NameValueCollection and If you give two key with same name default implementation will return latest value ( Last value in order for that key) but if you want to support multiple key support and you want it return all value for that key than you can replace appSettings default behavior with custom implementation.
http://www.codeproject.com/Articles/4302/How-to-make-AppSettings-work-with-multiple-values
But In case of connection string it is sealed class ConnectionStringSettingsCollection.
It is implement to support only one key with same name present and at web.config level it allow duplicate value for name but when you try to access it will throw error. It make sense in connection string case as well otherwise it get confused which to choose.
As per my point it is just implementing different way to support and reduce confusion.
Upvotes: 1