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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:21:35+00:00 2026-06-14T07:21:35+00:00

I’m wondering how the ConfigurationManager.AppSettings[Key] works. Does it read from the physical file each

  • 0

I’m wondering how the ConfigurationManager.AppSettings[Key] works.

Does it read from the physical file each time I need a key? If so, should I be reading all the app settings of my web.config in a cache and then read from it?

Or does ASP.NET or IIS load the web.config file only once at application startup?

How do I verify whether the physical file is accessed by each read? If I change the web.config, IIS restarts my application, so I can’t verify it that way.

  • 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-06-14T07:21:36+00:00Added an answer on June 14, 2026 at 7:21 am

    It gets cached, on first access of a property, so it does not read from the physical file each time you ask for a value. This is why it is necessary to restart an Windows app (or Refresh the config) to get the latest value, and why an ASP.Net app automatically restarts when you edit web.config. Why ASP.Net is hard wired to restart is discussed in the references in the answer How to prevent an ASP.NET application restarting when the web.config is modified.

    We can verify this using ILSpy and looking at the internals of System.Configuration:

    public static NameValueCollection AppSettings
    {
        get
        {
            object section = ConfigurationManager.GetSection("appSettings");
            if (section == null || !(section is NameValueCollection))
            {
                throw new ConfigurationErrorsException(SR.GetString("Config_appsettings_declaration_invalid"));
            }
            return (NameValueCollection)section;
        }
    }
    

    At first, this does indeed look like it will get the section every time. Looking at GetSection:

    public static object GetSection(string sectionName)
    {
        if (string.IsNullOrEmpty(sectionName))
        {
            return null;
        }
        ConfigurationManager.PrepareConfigSystem();
        return ConfigurationManager.s_configSystem.GetSection(sectionName);
    }
    

    The critical line here is the PrepareConfigSystem() method; this initializes an instance of the IInternalConfigSystem field held by the ConfigurationManager – the concrete type is ClientConfigurationSystem

    As part of this load, an instance of the Configuration class is instantiated. This class is effectively an object representation of the config file, and appears to be held by the ClientConfigurationSystem’s ClientConfigurationHost property in a static field – hence it is cached.

    You could test this empirically by doing the following (in a Windows Form or WPF app):

    1. Starting your App up
    2. Access a value in app.config
    3. Make a change to app.config
    4. Check to see whether the new value is present
    5. Call ConfigurationManager.RefreshSection("appSettings")
    6. Check to see if the new value is present.

    In fact, I could have saved myself some time if I’d just read the comment on the RefreshSection method 🙂

    /// <summary>Refreshes the named section so the next time that it is retrieved it will be re-read from disk.</summary>
    /// <param name="sectionName">The configuration section name or the configuration path and section name of the section to refresh.</param>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.