Click here to Skip to main content
15,887,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<appSettings>
  <add key="MongoCon" value="mongodb://asif:pass?@cluster0-shard-00-00.k6lme.mongodb.net:27017,cluster0-shard-00-01.k6lme.mongodb.net:27017,cluster0-shard-00-02.k6lme.mongodb.net:27017/myFirstDatabase?ssl=true&replicaSet=atlas-9yuzik-shard-0&authSource=admin&retryWrites=true&w=majority"/>
</appSettings>


But Compiler gives at & symbol in MongoCon value.

How to resolve it.

What I have tried:

I've tried \& to let compiler recognize its simple & sign, not a special sign.
Posted
Updated 2-Jun-21 22:13pm

The config file is an XML file. Any values stored within it need to be properly XML-encoded.

To add an & sign in an XML file, you need to use &amp;.
XML
<add key="MongoCon" value="...?ssl=true&replicaSet=...-shard-0&amp;authSource=admin&amp;retryWrites=true&amp;w=majority"/>
 
Share this answer
 
For XML, "&" is a special character that "describes" other special characters - this si known as an "escape character" just as "\" is in a C# string.

To include an ampersand in your string, replace it with "&amp;":
XML
<appSettings>
  <add key="MongoCon" value="mongodb://asif:pass?@cluster0-shard-00-00.k6lme.mongodb.net:27017,cluster0-shard-00-01.k6lme.mongodb.net:27017,cluster0-shard-00-02.k6lme.mongodb.net:27017/myFirstDatabase?ssl=true&amp;replicaSet=atlas-9yuzik-shard-0&authSource=admin&retryWrites=true&w=majority"/>
</appSettings>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900