简体   繁体   中英

cdata in appSettings value attribute

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 .

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:

http://www.4guysfromrolla.com/articles/032807-1.aspx

Observed same error and resolved it by:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM