cdata in appSettings value attribute

4.1k views Asked by At

Including a CDATA attribute in the <appSettings> section, as follows, results in an error:

<add key="somejey">
 <value><CDATA...> <//value>
</add>

The need is due to fact that we want to specify REST service endpoints that contain querystring values with args. This would get processed in code with String.Format and substitute the args value.

I assume my only way out is to have a custom XML file and read that in and get my value rather then use the appsettings.

2

There are 2 answers

0
Seymour On

Based on a brief review, seems like you could add a Custom Configuration Section in your configuration file.

For example:

The configuration file might look like:

   <configuration>      
      <!-- Custom Configuration Section -->
      <configSections>
        <section name="myCustomConfigSection" type="CustomConfigSection"/>
      </configSections>      

      <CustomConfigSection myKey="SomeValue" />

And the definition of type "CustomConfigSection":

   public class CustomConfigSection : ConfigurationSection
   {
      [ConfigurationProperty("myKey")]
      public string myKey {get; set;}
   }

The following page seems to provide a comprehensive overview:

https://web.archive.org/web/20211020133931/https://www.4guysfromrolla.com/articles/032807-1.aspx

0
Ramanujam Allam On

Observed same error and resolved it by:

  • Removing duplicate configs from section
  • Removing extra/unused characters (by mistakenly entered)