Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6694569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:07:01+00:00 2026-05-26T06:07:01+00:00

I know that there are tons of links about creating custom configuration sections out

  • 0

I know that there are tons of links about creating custom configuration sections out there, and tens of related questions has been asked here before. But I couldn’t solve my problem.

I’m able to create custom configuration sections, which are like:

  <publicPaths>
    <paths>
      <add name="ProductServices" address="/services/productservices.asmx" />
      <add name="LoginByToken" address="LoginByToken.ashx" />
    </paths>
  </publicPaths>

However, as you see, the meet of this configuration section (which is the items added to it) are at the 3rd nested level. In other words, you should traverse publicPaths -> paths -> add to get to the element representing the item. But what I want is a 2-level nesting, like:

    <paths>
      <add name="ProductServices" address="/services/productservices.asmx" />
      <add name="LoginByToken" address="LoginByToken.ashx" />
    </paths>

What should I do?

Update: The code of my 3-level custom configuration section is:

public class PublicPaths : ConfigurationSection
{
    private static PublicPaths publicPaths = ConfigurationManager.GetSection("publicPaths") as PublicPaths;

    public static PublicPaths Instance
    {
        get { return publicPaths; }
    }

    [ConfigurationProperty("paths", IsRequired = false)]
    public PathCollection Paths
    {
        get { return this["paths"] as PathCollection; }
    }
}

public class PathCollection : ConfigurationElementCollection
{
    public Path this[int index]
    {
        get { return base.BaseGet(index) as Path; }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }
            base.BaseAdd(index, value);
        }
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new Path();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((Path)element).Name;
    }
}

public class Path : ConfigurationElement
{
    [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
    public string Name
    {
        get { return (string)this["name"]; }
        set { this["name"] = value; }
    }

    [ConfigurationProperty("address", IsRequired = true)]
    public string Address
    {
        get { return (string)this["address"]; }
        set { this["address"] = value; }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:07:02+00:00Added an answer on May 26, 2026 at 6:07 am

    You could try this code (it should work).

    public class PublicPaths : ConfigurationSection
    {
        [ConfigurationProperty("", IsRequired = false, IsKey = false, IsDefaultCollection = true)]
        public PathCollection Items
        {
            get { return ((PathCollection)(base[""])); }
            set { base[""] = value; }
        } 
    }
    
    [ConfigurationCollection(typeof(Path), CollectionType = ConfigurationElementCollectionType.BasicMapAlternate)]
    public class PathCollection : ConfigurationElementCollection
    {
        internal const string ItemPropertyName = "add";
    
        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.BasicMapAlternate; }
        }
    
        protected override string ElementName
        {
            get { return ItemPropertyName; }
        }
    
        protected override bool IsElementName(string elementName)
        {
            return (elementName == ItemPropertyName);
        }
    
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((Path)element).Name;
        }
    
        protected override ConfigurationElement CreateNewElement()
        {
            return new Path();
        }
    
        public override bool IsReadOnly()
        {
            return false;
        }
    
    } 
    
    public class Path : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name
        {
            get { return (string)this["name"]; }
            set { this["name"] = value; }
        }
    
        [ConfigurationProperty("address", IsRequired = true)]
        public string Address
        {
            get { return (string)this["address"]; }
            set { this["address"] = value; }
        }
    }
    

    with this configuration

    <configuration>
      <configSections>
            <section name="publicPaths" type="{type}, {namespace}" />
      </configSections> 
      <publicPaths>    
          <add name="ProductServices" address="/services/productservices.asmx" />
          <add name="LoginByToken" address="LoginByToken.ashx" />    
     </publicPaths>
    </configuration>
    

    You could then access the values through

        var config = ConfigurationManager.GetSection("publicPaths") as PublicPaths;
    
        foreach (Path s in config.Items)
        {
         //print   
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there are many Delphi database related questions available, but I'm considering
I know that there are tons of questions like this one, but I couldn't
I know that there are many free and not so free compression libraries out
I know that there are lots of examples out there on this, but they
I know there's tons of threads about this. And I read a few of
I know there is a lot of similar questions are tons of great answers
I know that there is no way to fully protect our code. I also
I know that there can be multiple values for an email, but I'm not
I know that there is an allocator for user applications than handles lots of
I know that there is no return type of the constructors in C++ However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.