Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using "&" in appSettings in web.config

I'm trying to store a website address in the appSettings section of the web.config file. The URL has two querystring paramters at the end of the URL so I need to use the & symbol. When I hard code the URL in the code file it works if I substitute "&". In the config file these letters are red. I've tried both "&" and "&" in the config and they both turn red and I can't read them from the code file. Can anyone tell me how to do this so that it works?

Thanks,

EDIT:

It looks like it's not reading anything from the appSettings. I'm using this line to retrieve the setting.

String surveyLink = ConfigurationManager.AppSettings["SatisfactionSurveyLink"];
like image 645
Ronald McDonald Avatar asked Nov 30 '22 08:11

Ronald McDonald


2 Answers

Given that the web.config file is XML itself, if you want a string to actually be & you need to effectively encode it twice. Try:

&

When the XML is decoded, this will convert to & in the string, which will then be decoded again to & appropriately, by the sounds of it. Having said that, it's not really clear why you need & in the URL rather than & if you're trying to give two separate query parameters.

like image 160
Jon Skeet Avatar answered Dec 02 '22 22:12

Jon Skeet


The problem was that I was using a web.config file when I should have been using an app.config file in my test project

like image 42
Ronald McDonald Avatar answered Dec 02 '22 20:12

Ronald McDonald