Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The simple answer is no, it doesn't always read it from the file. As some have suggested if the file is changed then IIS performs a restart but not always! If you want to guarantee that you are reading the very latest value from the file and not the cache you need to call something like this:</p> <pre><code>ConfigurationManager.RefreshSection("appSettings"); string fromFile = ConfigurationManager.AppSettings.Get(key) ?? string.Empty; </code></pre> <p>And an example I use in my code:</p> <pre><code>/// ====================================================================================== /// &lt;summary&gt; /// Refreshes the settings from disk and returns the specific setting so guarantees the /// value is up to date at the expense of disk I/O. /// &lt;/summary&gt; /// &lt;param name="key"&gt;The setting key to return.&lt;/param&gt; /// &lt;remarks&gt;This method does involve disk I/O so should not be used in loops etc.&lt;/remarks&gt; /// &lt;returns&gt;The setting value or an empty string if not found.&lt;/returns&gt; /// ====================================================================================== private string RefreshFromDiskAndGetSetting(string key) { // Always read from the disk to get the latest setting, this will add some overhead but // because this is done so infrequently it shouldn't cause any real performance issues ConfigurationManager.RefreshSection("appSettings"); return GetCachedSetting(key); } /// ====================================================================================== /// &lt;summary&gt; /// Retrieves the setting from cache so CANNOT guarantees the value is up to date but /// does not involve disk I/O so can be called frequently. /// &lt;/summary&gt; /// &lt;param name="key"&gt;The setting key to return.&lt;/param&gt; /// &lt;remarks&gt;This method cannot guarantee the setting is up to date.&lt;/remarks&gt; /// &lt;returns&gt;The setting value or an empty string if not found.&lt;/returns&gt; /// ====================================================================================== private string GetCachedSetting(string key) { return ConfigurationManager.AppSettings.Get(key) ?? string.Empty; } </code></pre> <p>This allows you to very easily choose (and when reading code see) whether you are getting the latest value each time or if you don't expect the value to change from when the application starts.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload