So I've provided 2 ways of finding out what you want. Looking through any key in appsettings regardless of the key name, and then finding the specific value of the key by keyname.
My appsettings:
<appSettings>
<add key="KeyList" value="123,234,345,456"/>
<add key="AnotherSetting" value="123,234,345,456"/>
</appSettings>
Searching through all keys to find any key with a value of 123
var allkeys = ConfigurationManager.AppSettings.AllKeys;
foreach (var key in allkeys)
{
var value = ConfigurationManager.AppSettings[key];
if (value.Contains("123"))
{
Console.WriteLine("My app setting has a value of 123 on key {0}", key);
}
}
Picking the key by a specified name and checking the value.
var specificKey = ConfigurationManager.AppSettings["KeyList"];
if (!string.IsNullOrEmpty(specificKey) && specificKey.Contains("123"))
{
Console.WriteLine("KeyList contains 123");
}
Then if you are sure that all keys in your appsettings will be a CSV. You can do something like this to find any key that contains 123 (not 123456).
var csvKey = ConfigurationManager.AppSettings.AllKeys;
foreach (var key in csvKey)
{
var values = ConfigurationManager.AppSettings[key].Split(',');
foreach (var item in values)
{
if (item == "123")
{
Console.WriteLine("My app setting has a value of 123 on key {0}", key);
}
}
}