How can we add list or multiple values for a single key in web.config?
For example: I have key named "xyz" it has a list of values, that is , val1, val2, val3 etc.
And this can be obtained in my code as other keys are accessible.
Yes you can have two web. config files in application. There are situations where your application is divided in to modules and for every module you need separate configuration. For example if you have a application which has two modules lets say accounts and sales.
You can have multiple configuration files in your asp.net project. There is no restriction to use the web. config file in the asp.net web application.
Add in web config as comma separated valued like
<add key = "xyz" value="val1, val2, val3"/>
access them as
string[] xyzValues = System.Configuration.ConfigurationManager.AppSettings["xyz"].Split(",");
You can use the appsettings tag
<appSettings>
<add key="xyz" value="val1;val2;val3" />
</appSettings>
C# Code
string[] values = ConfigurationManager.AppSettings["xyz"].Split(';');
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