title: Read appSettings section from Web.config file using WebConfigurationManager
body: <p>I'm developing a WinForm application with C# and .NET Framework 4.7.</p>
  
  <p>I want to open a Web.config file, read its appSetting section and modify it.</p>
  
  <p>To open it, I use this:</p>
  
  <pre><code> System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
  </code></pre>
  
  <p>It opens it but, when I try to get the keys with:</p>
  
  <pre><code>string[] keys = config.AppSettings.Settings.AllKeys;
  </code></pre>
  
  <p>I get a null array.</p>
  
  <p>This is the appSetting section:</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
      &lt;sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
        &lt;section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;
        &lt;section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
  
    &lt;/connectionStrings&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
  
      &lt;add key="MinRemainingCodes" value="100" /&gt;
      &lt;!-- Others keys --&gt;
    &lt;/appSettings&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Maybe the problem is that it is not opening the file, but in the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.webconfigurationmanager.openwebconfiguration?view=netframework-4.7.2#System_Web_Configuration_WebConfigurationManager_OpenWebConfiguration_System_String_" rel="nofollow noreferrer">documentation</a> say:</p>
  
  <blockquote>
    <p>The virtual path to the configuration file. If null, the root
    Web.config file is opened.</p>
  </blockquote>
  
  <p>Maybe I don't understand what means with <code>root</code> because the program and the <code>Web.config</code> file are in the same folder.</p>
  
  <p>What am I doing wrong?</p>