Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have an ampersand sign in an appSettings key? error: web.config value is not defined

Tags:

I have the following appSettings section

<appSettings>   <add key="Foo" value="http://foo.bar.com/?app=xxx&FormName=yyy" /> </appSettings> 

But the IDE is giving me two errors:

  1. Error 25 Entity 'FormName' not defined.
  2. Error 26 Expecting ';'.

It seems the & is causing a problem. I'd like to not have to splt the values up into seperate keys. Is there an elegant way around this issue?

like image 432
WhiskerBiscuit Avatar asked Jun 06 '12 17:06

WhiskerBiscuit


People also ask

How do you exit ampersand in web config?

Use " &amp; " instead of "&".

Why Appsettings keys in web config are not case sensitive?

Why appsettings keys (in web. config) are not case sensitive ? The default comparer is a CaseInsensitiveComparer that uses the conventions of the invariant culture; that is, key comparisons are case-insensitive by default.

What is the use of Appsettings in web config?

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

You just need to use XML encoding here I believe - so & becomes &amp;

like image 58
RobV Avatar answered Oct 09 '22 04:10

RobV


Try &amp;  <appSettings>   <add key="Foo" value="http://foo.bar.com/?app=xxx&amp;FormName=yyy" /> </appSettings> 
like image 21
Adil Avatar answered Oct 09 '22 05:10

Adil