Following config file causes error because of & in ‘url’ value:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="url" value ="http://www.example.com/?user=admin&password=1234"/>
</appSettings>
</configuration>
The question is which encoding to use for key/value in a config file ? (i.e Url Encoding …)
This is an XML file. As such, you must XML-escape all reserved characters:
Programmatically you can perform this type of escaping using the
System.Web.HttpUtility.HtmlEncodemethod. Yes, its name suggests HTML specific encoding, but in my experience this is equivalent to XML escaping.