How to Read Items into Arrays in web.config

Viewed 2382

I'm trying to build an array of strings from items in a web.config file (in IIS).

web.config

<appSettings>
    <add key="favourite" value="url1; site1" />
    <add key="favourite" value="url2; site2" />
    <add key="favourite" value="url3; site3" />
</appSettings>

C#

// Reads first favourite into string.
public string _favourites = ConfigurationManager.AppSettings ["favourite"];

I would like each favourite to be read into string [ ] _favourites array with the semi-colon (I would parse that out later). web.config is an XML file so I can open it as one and pull the data out, but is there an easier way to do this using ConfigurationManager?

3 Answers
Related