"Complex" URL in App.config-file

M

Michael Barrett

Hi,

Using C# I need to retrieve a setting from my App.config-file (console
application). The key I need to retrieve is shown below.

<appSettings>
<add key="HtmlString"
value=@"http://ADDRESS.com/opdat.php?name=NAME&domain=DOMAIN&pw=PW&silent=1"
/>
</appSettings>

I use the following code to retrieve the setting.

string htmlString = ConfigurationSettings.AppSettings["HtmlString"];

However, I get a runtime error doing this (ConfigurationException). If I
replace the value in the key with something more simple - such as "Test" for
example, it works fine. This leads me to believe that it somehow is the
composition of the URL that is the problem... But what can I do to solve it?

Thanks in advance.
 
M

Michael Barrett

Using C# I need to retrieve a setting from my App.config-file (console
application). The key I need to retrieve is shown below.

<appSettings>
<add key="HtmlString"
value=@"http://ADDRESS.com/opdat.php?name=NAME&domain=DOMAIN&pw=PW&silent=1"
/>
</appSettings>

I use the following code to retrieve the setting.

string htmlString = ConfigurationSettings.AppSettings["HtmlString"];

However, I get a runtime error doing this (ConfigurationException).
If I replace the value in the key with something more simple - such
as "Test" for example, it works fine. This leads me to believe that
it somehow is the composition of the URL that is the problem... But
what can I do to solve it?

Well.... I have traced the problem to the ampersands (&) in the URL. When I
remove them it works fine... However - I need them in the URL for it to
work. Is there a way around that? And also... The "@" before the URL has
been removed. It was an error... :)
 
C

Conrad Zhang

http://www.w3.org/TR/REC-xml

2.4 Character Data and Markup
The ampersand character (&) and the left angle bracket (<) may appear in
their literal form only when used as markup delimiters, or within a comment,
a processing instruction, or a CDATA section. If they are needed elsewhere,
they must be escaped using either numeric character references or the
strings "&amp;" and "&lt;" respectively. The right angle bracket (>) may be
represented using the string "&gt;", and must, for compatibility, be escaped
using "&gt;" or a character reference when it appears in the string "]]>" in
content, when that string is not marking the end of a CDATA section.


Michael Barrett said:
Using C# I need to retrieve a setting from my App.config-file (console
application). The key I need to retrieve is shown below.

<appSettings>
<add key="HtmlString"
value=@"http://ADDRESS.com/opdat.php?name=NAME&domain=DOMAIN&pw=PW&silent=1"
/>
</appSettings>

I use the following code to retrieve the setting.

string htmlString = ConfigurationSettings.AppSettings["HtmlString"];

However, I get a runtime error doing this (ConfigurationException).
If I replace the value in the key with something more simple - such
as "Test" for example, it works fine. This leads me to believe that
it somehow is the composition of the URL that is the problem... But
what can I do to solve it?

Well.... I have traced the problem to the ampersands (&) in the URL. When I
remove them it works fine... However - I need them in the URL for it to
work. Is there a way around that? And also... The "@" before the URL has
been removed. It was an error... :)
 
M

Michael Barrett

Conrad said:
http://www.w3.org/TR/REC-xml

2.4 Character Data and Markup
The ampersand character (&) and the left angle bracket (<) may appear
in their literal form only when used as markup delimiters, or within
a comment, a processing instruction, or a CDATA section. If they are
needed elsewhere, they must be escaped using either numeric character
references or the strings "&amp;" and "&lt;" respectively. The right
angle bracket (>) may be represented using the string "&gt;", and
must, for compatibility, be escaped using "&gt;" or a character
reference when it appears in the string "]]>" in content, when that
string is not marking the end of a CDATA section.


value=@"http://ADDRESS.com/opdat.php?name=NAME&domain=DOMAIN&pw=PW&silent=1"
/>
</appSettings>

I use the following code to retrieve the setting.

string htmlString = ConfigurationSettings.AppSettings["HtmlString"];

However, I get a runtime error doing this (ConfigurationException).
If I replace the value in the key with something more simple - such
as "Test" for example, it works fine. This leads me to believe that
it somehow is the composition of the URL that is the problem... But
what can I do to solve it?

Well.... I have traced the problem to the ampersands (&) in the URL.
When I remove them it works fine... However - I need them in the URL
for it to work. Is there a way around that? And also... The "@"
before the URL has been removed. It was an error... :)

Thanks a lot Conrad... That fixed it! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top