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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:15:03+00:00 2026-05-22T21:15:03+00:00

With the release of .NET4 has anyone ever created a dynamic web.config element that

  • 0

With the release of .NET4 has anyone ever created a dynamic web.config element that will just let you type anything you want into the config and then you can access it all off a dynamic object?

The amount of work that goes into creating custom config sections is just over the top for seemingly no reason. This has lead me to wonder if someone has replaced the song and dance of easily needing to create 5+ classes to roll a new config section each and every time.

(Note, when I say free form I would obviously expect it to conform to a valid xml element)

  • 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-22T21:15:03+00:00Added an answer on May 22, 2026 at 9:15 pm

    If you just want to access the appSettings section of the configuration file, you can inherit from the DynamicObject class and override the TryGetMember method:

    public class DynamicSettings : DynamicObject {
        public DynamicSettings(NameValueCollection settings) {
            items = settings;
        }
    
        private readonly NameValueCollection items;
    
        public override bool TryGetMember(GetMemberBinder binder, out object result) {
            result = items.Get(binder.Name);
            return result != null;
        }
    }
    

    Then, assuming this is your app.config file:

    <configuration>
      <appSettings>
        <add key="FavoriteNumber" value="3" />
      </appSettings>
    </configuration>
    

    … the ‘FavoriteNumber’ setting could be accessed like so:

    class Program {
        static void Main(string[] args) {
            dynamic settings = new DynamicSettings(ConfigurationManager.AppSettings);
            Console.WriteLine("The value of 'FavoriteNumber' is: " + settings.FavoriteNumber);
        }
    }
    

    Note that attempting to access a key that is undefined results in a RuntimeBinderException being thrown. You could prevent this by changing the overridden TryGetMember to always return true, in which case undefined properties will simply return null.

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

Sidebar

Related Questions

I'm building a product that will ship after .Net 4.0 is released. Is MEF
In Release It! , Michael Nygard reasons that many catastrophic system failures are often
I have a TFS 2008 Build Agent that has been used to build .Net
I am about to release my pet project and let other people to use
Will their be a new release of the compact framework with VS2010 and .net
With the upcoming release of .NET 4 in mind, what are the reasons that
I have a .net wpf app that I am deploying, including the .net4 client
Does anyone know if the types in the .NET 4.0 release of System.Windows.Forms.DataVisualization can
We should have a full release of asp.net MVC well before .NET 4.0 and
Since the 2.6.1 .NET 4.0 RC release of IronPython (found @ http://ironpython.codeplex.com/releases/view/40146 ) does

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.