I have this list say product Type:
Type1
Type2
Type3
and so on Now this list will keep increasing time to time and will be set via appsettings.
Now the key will not be really like Type1 orType2 these will be different. Like say
<add key="FoodItems" value="something"/>
<add key="Cosmetics" value="xyz"/>
so on.. So when I write the code i need to get the key and value from app config, I know how to get all keys but I want to put these under certain category so that I don't have to Parse the whole config file I will parse just this section and get all the types under it.
something like
<ItemList>
<add key="FoodItems" value="something"/>
<add key="Cosmetics" value="xyz"/>
</ItemList>
Is it possible to do something like that in appsettings? Or some other way but yes in appconfig specifically.
Open the App. config file and add the configSections, sectionGroup and section to it. We need to specify the name and fully qualified type of all the section and section group.
AppSetting section in the configuration file is a section that allows us to keep configurable and application wide settings (for e.g.: ConnectionString) that an application requires in order to perform the tasks properly. This helps in easy maintenance and deployment of the application.
Why appsettings keys (in web. config) are not case sensitive ? The default comparer is a CaseInsensitiveComparer that uses the conventions of the invariant culture; that is, key comparisons are case-insensitive by default.
What you want is your own custom Configuration Section. Here is a solid guide I've used before.
When using your own configuration section, you don't have to use a Dictionary
type like appSettings does - you can define multiple properties, which sounds like what you are looking for.
An alternative is using sectiongroup element as indicated here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With