Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing appSettings from multiple Web.config files
    primarykey
    data
    text
    <p>I am designing an ASP.NET MVC4 Web App project. In the root of my project, I have the customary default <code>Web.config</code> file with my corresponding elements. In particular, I have a few <code>appSettings</code> elements defined. As an example excerpt to demonstrate this:</p> <pre><code>&lt;appSettings&gt; &lt;add key="foo" value="bar" /&gt; &lt;/appSettings&gt; </code></pre> <p>Naturally, I can access this element within code using <code>ConfigurationManager.AppSettings["foo"]</code>. This works perfectly for me. However, I am creating a NuGet package alongside my project. The package is installed within its own directory under my project's <code>Areas</code> directory. Here, in my package's root, I have another <code>Web.config</code> file. This is so that, when another user imports the NuGet package, the configuration for the package resources is native to the package. Let the package's <code>Web.config</code> contain the following:</p> <pre><code>&lt;appSettings&gt; &lt;add key="dirEnabled" value="true" /&gt; &lt;/appSettings&gt; </code></pre> <p>Just to clarify in terms of relative paths, I now have two Web.config files, one at <code>./Web.config</code> and one at <code>./Areas/PackageName/Web.config</code>.</p> <p>Within my package, I want to retrieve the value for <code>dirEnabled</code>. To do so, I make the call: <code>ConfigurationManager.AppSettings["dirEnabled"]</code>. However, this throws an error. It appears as if only the collection of appSettings is being retrieved from <code>./Web.config</code> and not my package config file. <strong>Is it at all possible to grab the appSettings collection from my package's config file rather than the project root config file?</strong></p>
    singulars
    1. This table or related slice is empty.
    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. 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