Coder Perfect

In an app config file, how do I add an ampersand to a value?


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…

  <add key="myurl" value=""/>

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?

  <add key="myurl" value=";cid=&amp;sid="/>

Answered by BenAlabaster

Solution #3

You should be allowed to utilize the HTML escape character, in my opinion (&). 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