How to open a config file app settings using ConfigurationManager? <p>My config file is located here:</p> <pre><code>"~/Admin/Web.config" </code></pre> <p>I tried opening it via the below code but it didn't work:</p> <pre><code>var physicalFilePath = HttpContext.Current.Server.MapPath("~/Admin/Web.config"); var configMap = new ConfigurationFileMap(physicalFilePath); var configuration = ConfigurationManager.OpenMappedMachineConfiguration(configMap); var appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings"); </code></pre> <p>when appsettings line runs, it throws the below error message:</p> <pre><code>Unable to cast object of type 'System.Configuration.DefaultSection' to type 'System.Configuration.AppSettingsSection'. </code></pre> <p>My Web.Config looks like below:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"&gt; &lt;appSettings&gt; &lt;add key="AdminUsername" value="Test1"/&gt; &lt;add key="AdminPassword" value="Test2"/&gt; &lt;/appSettings&gt; &lt;connectionStrings&gt;&lt;/connectionStrings&gt; &lt;/configuration&gt; </code></pre> <p>How could I get the appsettings?</p>