在App.Config中使用哪种编码? [英] Which encoding to use in App.Config?
本文介绍了在App.Config中使用哪种编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于&
,以下 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>
问题是 config
文件中的键/值
使用哪种编码?(即网址编码...)
The question is which encoding to use for key/value
in a config
file ? (i.e Url Encoding ...)
推荐答案
这是一个XML文件.因此,您必须XML保留所有保留字符:
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&password=1234"/>
</appSettings>
</configuration>
通过编程,您可以使用 System.Web.HttpUtility.HtmlEncode
方法执行这种转义.是的,它的名字暗示了HTML特定的编码,但是以我的经验,这等同于XML的转义.
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.
这篇关于在App.Config中使用哪种编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文