Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Try This:</h2> <p>Put a breakpoint where your ConfigurationManager statement is and run the following in the Immediate Output window <code>((ConfigurationSection) ConfigurationManager.GetSection("connectionStrings")).ElementInformation</code> . My machine reports <strong><em>Source:</strong> "C:\Users\John\Documents\Visual Studio 2008\Projects\StackOverflowCode\WebApplication1\web.config"</em> as seen below.</p> <p><strong>Note: The following also shows mine is accessing the ASP.NET web.config.</strong></p> <pre><code>{System.Configuration.ElementInformation} Errors: {System.Configuration.ConfigurationException[0]} IsCollection: true IsLocked: false IsPresent: true LineNumber: 17 Properties: {System.Configuration.PropertyInformationCollection} Source: "C:\\Users\\John\\Documents\\Visual Studio 2008\\Projects\\StackOverflowCode\\WebApplication1\\web.config" Type: {Name = "ConnectionStringsSection" FullName = "System.Configuration.ConnectionStringsSection"} Validator: {System.Configuration.DefaultValidator} </code></pre> <p>And when I run <code>ConfigurationManager.ConnectionStrings.ElementInformation</code> I get <strong><em>Source</strong>:null</em> which is correct for my web app.</p> <p>What do you get for a configuration Source path???</p> <hr> <h2>Immediate Assumption</h2> <p><code>ConfigurationManager.ConnectionStrings["connectionString"];</code> might look for a config location which isn't necessarily the same as the web application's root web.config. Likely it's looking in a Windows directory (e.g at a different place or for machine.config). Trying to find an appropriate test for this though.</p> <hr> <h2>Intentions of Each Manager</h2> <p><a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager(VS.80).aspx" rel="noreferrer">System.Configuration.<strong>ConfigurationManager</strong></a> can access the .NET configuration XML format which means it reads both:</p> <ul> <li>web configurations (i.e. web.config file in ASP.NET) </li> <li>and non-web configurations (e.g. app.config file - standalone console app, Windows app, etc.) </li> </ul> <p>and expresses those aspects that are common to types of configuration. This is a general purpose config manager. <em>(However despite this ability to look at both types of configs, you should use it for app configs because the web manager is devoted to the web configs, as described next ...)</em></p> <p><a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.webconfigurationmanager(VS.80).aspx" rel="noreferrer">System.Web.Configuration.<strong>WebConfigurationManager</strong></a> does pretty much the same thing but is the "webified" version of configuration manager, providing access to ASP.NET web-specific aspects of configuration (e.g. web.config file in ASP.NET). </p> <h2>Similarities</h2> <p>See member similarities between <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager_members(VS.80).aspx" rel="noreferrer">ConfigurationManager.*</a> and <a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.webconfigurationmanager_members(VS.80).aspx" rel="noreferrer">WebConfigurationManager.*</a> </p> <p>Both managers can, for example, access an <code>AppSettings</code> property and a <code>ConnectionStrings</code> property. Indeed both these settings are common to both kinds of config and are even located at the same level in the XML document.</p> <p>So there are many similarities however,</p> <h2>Behavioral Differences</h2> <p><strong>Accessing configuration</strong>: ConfigurationManager has methods to open standalone app configs (i.e. Myprogram.EXE's App.config) relative to the EXEC app, whereas WebConfigurationManager has methods to open the ASP.NET web config relative to it's web application root directory in the web site. </p> <p>Here's a basic <strong>app.config</strong> (e.g. opened via "C:\winapp\app.config" from a disk folder by <strong>ConfigurationManager</strong>)</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;appSettings/&gt; &lt;connectionStrings/&gt; &lt;/configuration&gt; </code></pre> <p>And here's a basic <strong>web.config</strong> (e.g. opened via "~" meaning root of web site by <strong>WebConfigurationManager</strong>)</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;appSettings/&gt; &lt;connectionStrings/&gt; &lt;system.web&gt; &lt;!-- special web settings --&gt; &lt;/system.web&gt; &lt;/configuration&gt; </code></pre> <p>Notice the similarities. Also notice the web configuration has an additional <code>system.web</code> element for ASP.NET.</p> <p>These managers are located in <strong>different</strong> assemblies.</p> <ul> <li>ConfigurationManager: <strong>System.Configuration.dll</strong></li> <li>WebConfigurationManager: <strong>System.Web.dll</strong></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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