(ASP.NET) Can you create String.Format in web.config file / value?

This may be a terrible question from God, but I'm not sure why this will not allow me to do this.

I have a url that I need to save in Web.config, which has a dynamic parameter pulled from a web page.

So I want to save:

<add key="TestURL" value="https://test/subscribe?msisdn={0}&code=1&pass=2"/> 

This does not allow me to do this. After {0} these are errors on "&".

Can someone tell me what I'm doing wrong here? Do I need to avoid the character?

+4
source share
2 answers

Try instead

 <add key="TestURL" value="https://test/subscribe?msisdn={0}&amp;code=1&amp;pass=2"/> 

Pay attention to shielded ampersands.

+12
source

Configuration files are XML and, as such, require XML objects to be escaped. The problem is not your {0} for use in formatting, but that it should be escaped as

 &amp; 
+3
source

All Articles