简体   繁体   English

appSettings值属性中的cdata

[英]cdata in appSettings value attribute

Including a CDATA attribute in the <appSettings> section, as follows, results in an error: 如下所示,在<appSettings>部分中包含CDATA属性会导致错误:

<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. 需要是由于事实,因为我们要指定包含带有args的querystring值的REST服务端点。 This would get processed in code with String.Format and substitute the args value. 这将使用String.Format在代码中进行处理,并替换为args值。

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 . 我认为我唯一的出路是拥有一个自定义XML文件并读入该文件并获取我的价值,而不是使用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": 以及类型“ 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 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) 删除多余/未使用的字符(错误输入)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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