views:

207

answers:

2

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}&amp;code=1&amp;pass=2"/&gt;

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?

+5  A: 

Try this instead,

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

Notice the escaped ampersands.

Brandon
@JackM whatever values you want to place in the add tag value attribute just need to be HTML encoded. If you have a hard time figuring out how to encode a value properly you can write something that will have .Net do it for you using the HttpServerUtility.HtmlEncode method: http://msdn.microsoft.com/en-us/library/w3te6wfz.aspx
Spencer Ruport
+1  A: 

Config files are XML, and as such, require XML entities to be escaped. The problem isn't your {0} for use in formatting, it's the & that must be escaped as

&amp;
jpj625