How can I add an ampersand for a value in a ASP.net/C# app config file value


Question

I've got a C# program with values in a config file. What I want is to store ampersands for an url value like...

<appSettings>
  <add key="myurl" value="http://www.myurl.com?&cid=&sid="/>
</appSettings>

But I get errors building my site. The ampersand is not allowed. I've tried various forms of escaping the ampersands to no avail. Anyone know of the correct form to do this? All suggestions are welcome.

1
197
12/17/2008 9:45:28 PM

Accepted Answer

Use "&amp;" instead of "&".

394
12/17/2008 9:46:33 PM

Have you tried this?

<appSettings>  
  <add key="myurl" value="http://www.myurl.com?&amp;cid=&amp;sid="/>
<appSettings>

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon