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 872177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:44:44+00:00 2026-05-15T10:44:44+00:00

Apologies in advance for the relatively long post – I’ve tried to provide as

  • 0

Apologies in advance for the relatively long post – I’ve tried to provide as much relevant information as I can (including code listings)!

I’ve been working on implementing a custom section in the web.config file for a little something I’m working for the past few hours, but I can’t seem to get it working. The following is what I’d like to use as my XML structure:

<mvcmodules>
    <module moduleAlias="name" type="of.type">
        <properties>
            <property name="propname" value="propvalue" />
        </properties>
    </module>
</mvcmodules>

Currently, I have the following classes set up and working (somewhat):

  • ModuleSection
  • ModuleCollection
  • Module
  • ModulePropertyCollection
  • ModuleProperty

The only way I can see to get close to the way I want to do this is to wrap my declarations in another parent called . However, when I do this, I get an error if I have more than one instance of the tag (“The element may only appear once in this section.”), and with one tag, the information is not being read in to the objects.

I’ve written a little basic documentation so you can get an idea of how I’m structuring this and hopefully see where I’m going wrong

ModuleSection
This class holds a ModulesCollection object

namespace ASPNETMVCMODULES.Configuration
{
    public class ModulesSection : System.Configuration.ConfigurationSection
    {
        [ConfigurationProperty("modules", IsRequired = true)]
    public ModuleCollection Modules
    {
        get
        {
            return this["modules"] as ModuleCollection;
        }
    }
}

ModulesCollection
Holds a collection of Module objects

namespace ASPNETMVCMODULES.Configuration
{
public class ModuleCollection : ConfigurationElementCollection
{
    [ConfigurationProperty("module")]
    public Module this[int index]
    {
        get
        {
            return base.BaseGet(index) as Module;
        }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }

            this.BaseAdd(index, value);
        }
    }

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

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((Module)element).ModuleAlias;
    }
}

}

Module
Contains information about the module and a ModulePropertyCollection object

    public class Module : ConfigurationElement
{
    [ConfigurationProperty("moduleAlias", IsRequired = true)]
    public string ModuleAlias
    {
        get
        {
            return this["moduleAlias"] as string;
        }
    }

    [ConfigurationProperty("type", IsRequired = true)]
    public string ModuleType
    {
        get
        {
            return this["type"] as string;
        }
    }

    [ConfigurationProperty("properties")]
    public ModulePropertyCollection ModuleProperties
    {
        get
        {
            return this["properties"] as ModulePropertyCollection;
        }
    }
}

ModulePropertyCollection
Contains a collection of ModuleProperty objects

    public class ModulePropertyCollection : ConfigurationElementCollection
{
    public ModuleProperty this[int index]
    {
        get
        {
            return base.BaseGet(index) as ModuleProperty;
        }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }

            this.BaseAdd(index, value);
        }
    }

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

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

ModuleProperty
Holds information about the module properties

    public class ModuleProperty : ConfigurationElement
{
    [ConfigurationProperty("name", IsRequired = true)]
    public string Name
    {
        get
        {
            return this["name"] as string;
        }
    }

    [ConfigurationProperty("value", IsRequired = true)]
    public string Value
    {
        get
        {
            return this["value"] as string;
        }
    }
}
  • 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-15T10:44:45+00:00Added an answer on May 15, 2026 at 10:44 am

    I think you need to create a property decorated with the ConfigurationCollectionAttribute attribute. I scanned your code and didn’t see a reference to it anywhere.

    The MSDN link for once actually has a useful example. I recently put together a custom config section myself, and found that page entirely adequate. See my question for how to enable Intellisense support for your config section in Visual Studio.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies in advance for rather long post and lot of code. My application has
I'm fairly new to Python, so my apologies in advance if this is much
First, a thank you in advance. Second, this is my first post so apologies
Apologies in advance if this is a silly question, am very much a beginner.
Apologies in advance if this is obvious, but I can't seem to find an
OK, apologies in advance for posting a huge chunk of code! My problem is
This is my first post. Apologies in advance if my question is dumb. I'm
Apologies in advance if this has been addressed before, but I've tried looking through
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Apologies in advance for a long question: I do want to give all the

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.