Problem
I’ve got a C# program with config file values. What I’m looking for is a way to save ampersands for url values such…
<appSettings>
<add key="myurl" value="http://www.myurl.com?&cid=&sid="/>
</appSettings>
However, when I try to develop my site, I get issues. The use of an ampersand is not permitted. I’ve done everything I can think of to get around the ampersands, but it’s not working. Anyone know what the proper format is for this? Any and all ideas are welcome.
Asked by Rob Segal
Solution #1
In place of “&,” use “&.”
Answered by Eric Rosenberger
Solution #2
Have you ever done something like this?
<appSettings>
<add key="myurl" value="http://www.myurl.com?&cid=&sid="/>
<appSettings>
Answered by BenAlabaster
Solution #3
You should be allowed to utilize the HTML escape character, in my opinion (&). http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php has them.
Answered by ICR
Solution #4
Although the accepted answer is technically correct, the comments indicate that there is some uncertainty among users. When working with a ViewBag in a.cshtml file, you must use @Html.Raw, else your data will be re-escaped after being unescaped by the ConfigurationManager. To prevent this from happening, use Html.Raw().
Answered by user700390
Post is based on https://stackoverflow.com/questions/376135/how-can-i-add-an-ampersand-for-a-value-in-a-asp-net-c-app-config-file-value