【问题标题】:custom tags in web.configweb.config 中的自定义标签
【发布时间】:2016-09-21 19:49:14
【问题描述】:

我使用如下所示的配置文件在 web.config 文件中创建了自定义标签:

<ParentTag>
    <ChildTag>
        <add param1="some value" param2="some value" param3="some value />
        <add param1="some other value" param2="some other value" param3="some other value">
    </ChildTag>
<ParentTag>

我想知道是否可以创建这样的东西:

<ParentTag>
    <ChildTag_1>
        <add param1="some value" param2="some value" param3="some value" />
        <add param1="some other value" param2="some other value" param3="some other value">
    </ChildTag_1>

    <ChildTag_2>
        <add param1="some value" param2="some value" param3="some value" />
        <add param1="some other value" param2="some other value" param3="some other value">
    </ChildTag_2>
<ParentTag>

为了实现这一点,我应该对配置文件进行哪些更改?或者这根本无法实现?谁能解释一下

我点击此链接创建自定义标签:

http://code.tutsplus.com/tutorials/how-to-add-custom-configuration-settings-for-an-aspnet-application--net-9590

【问题讨论】:

  • 您有什么特别的原因不只是使用appSettings 部分吗?
  • 好吧,看起来您想在配置部分创建集合集合。你可以这样做。但它看起来很奇怪。
  • @MaKCbIMKo 这可能看起来很奇怪,但我可以证明这样的结构有它的用处。这一切都取决于你如何命名事物,以及它看起来有多奇怪。
  • @Hill 你没有在appSettings 上获得 Intellisense 支持。
  • 那你不能使用 appSettings 和自定义类型 AFAIK

标签: c# web-config configuration-files custom-tags


【解决方案1】:

如示例中所述,通过提要项使用 ConfigurationElementCollection。

public class FeedElementCollection : ConfigurationElementCollection

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-13
    • 2015-01-03
    • 2021-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多