Is Web.config's appSettings section only capable of storing simple strings like this?
<appSettings>
<add key="OKPage" value="http://mysite.com/okpage.html" />
</appSettings>
or I can have more complex values like CDATA or nested values? If not, is this the only place in Web.config where to store custom settings? Thanks
You can make any XmlSerializable class as a setting.
I answered to the similar question here: Custom type application settings in ASP.NET
Also there is a sample project attached.
Here is an example of the settings from my config file:
<setting name="MyEndPoints"
serializeAs="Xml">
<value>
<ArrayOfEndPoint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EndPoint>
<HostName>10.40.10.9</HostName>
<Port>22634</Port>
</EndPoint>
<EndPoint>
<HostName>10.40.10.9</HostName>
<Port>22635</Port>
</EndPoint>
</ArrayOfEndPoint>
</value>
</setting>
Custom class for settings:
public class EndPoint
{
public string HostName { get; set; }
public int Port { get; set; }
}
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