0

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

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

配置看起来像:

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

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

4

1 回答 1

2

您需要像这样在 app.config 中编码您的值

<add key="Password" value="exam&amp;ple"/>
于 2012-07-26T17:04:08.977 回答