rad*_*byx 29 c# configuration uri windows-services app-config
我正在做一个Windows Service.在Service每晚都要donwload东西,为此我要放置URI在App.config万一我以后需要改变它.
我想在App.Config中编写一个URI.什么使它无效,我应该如何处理?
<appSettings>
<add key="fooUriString"
value="https://foo.bar.baz/download/DownloadStream?id=5486cfb8c50c9f9a2c1bc43daf7ddeed&login=null&password=null"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
我的错误:
- Entity 'login' not defined
- Expecting ';'
- Entity 'password' not defined
- Application Configuration file "App.config" is invalid. An error occurred
Run Code Online (Sandbox Code Playgroud)
Dai*_*Dai 62
您尚未在URI中正确编码&符号.请记住,这app.config是一个XML文件,因此您必须符合XML的转义要求(例如,&应该是&,<应该<和>应该>).
在你的情况下,它应该是这样的:
<appSettings>
<add
key="fooUriString"
value="https://foo.bar.baz/download/DownloadStream?id=5486cfb8c50c9f9a2c1bc43daf7ddeed&login=null&password=null"
/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
但一般来说,如果你想存储一个看起来像的字符串,"I <3 angle bra<kets & ampersands >>>"那么这样做:
<appSettings>
<add
key="someString"
value="I <3 angle bra<kets & ampersands >>>"
/>
</appSettings>
void StringEncodingTest() {
String expected = "I <3 angle bra<kets & ampersands >>>";
String actual = ConfigurationManager.AppSettings["someString"];
Debug.Assert.AreEqual( expected, actual );
}
Run Code Online (Sandbox Code Playgroud)