• Namespace: using System.Configuration;
  • Make sure to add the System.Configuration on the References of the solution file if it’s not yet added.

Sample web.config AppSettings keys and values:

webconfig

Sample Dog Class

dog

Sample usage on a web form’s drop down list

usage

Sample ASPX

aspnet


private Dog[] ListOfDogs
{

get
{

var appSettings = ConfigurationManager.AppSettings.AllKeys.Where(key => key.StartsWith(“Dog:”));

Dog[] dogs = new Dog[appSettings.Count()];

int i = 0;
foreach (String s in appSettings)
{

dogs [i] = new Dog();
dogs [i].key = s.Replace(“Dog:”,string.Empty);
dogs [i].value = ConfigurationManager.AppSettings[s];
i++;

}

return dogs;

}

}


Result

result