我正在制作Windows Service
。 Service
每晚必须下载一些东西,因此我想将URI放在App.Config中以防我以后需要更改它。
我想在App.Config中编写一个URI。什么使它无效,我应该如何处理?
<appSettings>
<add key="fooUriString"
value="https://foo.bar.baz/download/DownloadStream?id=5486cfb8c50c9f9a2c1bc43daf7ddeed&login=null&password=null"/>
</appSettings>
我的错误:
- Entity 'login' not defined
- Expecting ';'
- Entity 'password' not defined
- Application Configuration file "App.config" is invalid. An error occurred
答案 0 :(得分:61)
您尚未正确编码URI中的&符号。请记住,app.config
是一个XML文件,因此您必须符合XML对转义的要求(例如&
应为&
,<
应为<
和{ {1}}应为>
)。
在您的情况下,它应该如下所示:
>
但一般来说,如果你想存储一个看起来像<appSettings>
<add
key="fooUriString"
value="https://foo.bar.baz/download/DownloadStream?id=5486cfb8c50c9f9a2c1bc43daf7ddeed&login=null&password=null"
/>
</appSettings>
的字符串,那就这样做:
"I <3 angle bra<kets & ampersands >>>"
答案 1 :(得分:7)
尝试使用:&
代替网址中的&amp;
答案 2 :(得分:7)
&
应该可以正常使用,维基百科有List of predefined entities in XML。