开发者

Which encoding to use in App.Config?

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 开发者_C百科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:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key ="url" value ="http://www.example.com/?user=admin&amp;password=1234"/>
  </appSettings>
</configuration>

Programmatically you can perform this type of escaping using the System.Web.HttpUtility.HtmlEncode method. Yes, its name suggests HTML specific encoding, but in my experience this is equivalent to XML escaping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜