Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error parsing AppSettings value with a query string

In my AppSettings in web.config, I have something like this:

<appSettings>
    <add key="ExternalSystemUrl" value="http://domain.com/page.aspx?id={0}&action=eat&object=bacon" />
</appSettings>

However, it seems that when an ampersand (&) is included in an AppSettings value, ASP.NET throws the following error:

An error occurred while parsing EntityName

Why does this happen, and how can I include URLs like this in App.config?

like image 346
Brandon Avatar asked Jun 10 '11 12:06

Brandon


People also ask

What is appSettings?

The <appSettings> element stores custom application configuration information, such as database connection strings, file paths, XML Web service URLs, or any other custom configuration information for an application.


2 Answers

Replace & with &amp; (escape it):

<add
    key="ExternalSystemUrl"
    value="http://domain.com/page.aspx?id={0}&amp;action=eat&amp;object=bacon" />

That's the common requirement for any valid XML file.

See Where can I get a list of the XML document escape characters?

like image 159
abatishchev Avatar answered Oct 05 '22 16:10

abatishchev


You can Try using &amp; instead.

like image 29
Wicked Coder Avatar answered Oct 05 '22 16:10

Wicked Coder