繁体   English   中英

appSettings值属性中的cdata

[英]cdata in appSettings value attribute

如下所示,在<appSettings>部分中包含CDATA属性会导致错误:

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

需要是由于事实,因为我们要指定包含带有args的querystring值的REST服务端点。 这将使用String.Format在代码中进行处理,并替换为args值。

我认为我唯一的出路是拥有一个自定义XML文件并读入该文件并获取我的价值,而不是使用appsettings

根据简要的评论,您似乎可以在配置文件中添加“自定义配置”部分。

例如:

配置文件可能如下所示:

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

      <CustomConfigSection myKey="SomeValue" />

以及类型“ CustomConfigSection”的定义:

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

以下页面似乎提供了全面的概述:

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

观察到相同的错误并通过以下方法解决了它

  • 从部分中删除重复的配置
  • 删除多余/未使用的字符(错误输入)

暂无
暂无

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

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