Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(ASP.NET) Can you do a String.Format on a web.config key/value?

This might be a god awful question but I'm not sure why it won't let me do this.

I have a URL I need to store in Web.config, which has a dynamic parameter pulled from the web page.

So I want to store:

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

It doesn't let me do this. After the {0} it errors at the "&".

Can anyone let me know what I'm doing wrong here? Do I need to escape the character?

like image 925
Jack Marchetti Avatar asked Dec 08 '22 06:12

Jack Marchetti


1 Answers

Try this instead,

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

Notice the escaped ampersands.

like image 166
Brandon Avatar answered Apr 08 '23 11:04

Brandon