从应用程序配置文件中读取符号

时间:2012-07-26 17:00:53

标签: c# configuration-files

我正在使用我的C#应用​​程序从配置文件中读取密码(它是一个Windows服务)。我正在使用这些行:

private NameValueCollection appSettings = ConfigurationManager.AppSettings;
string password = appSettings["Password"];

配置如下:

<add key="Password" value="exam&ple" />

由于应用程序配置不正确,服务无法启动。如果我删除'&amp;',则该服务有效。我怎么能控制这个问题?感谢。

1 个答案:

答案 0 :(得分:2)

您需要在app.config中对您的值进行编码,如此

<add key="Password" value="exam&amp;ple"/>
相关问题