Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't actually specify <code>&lt;appSettings&gt;</code> in your <code>applicationHost.config</code> file. This is because <code>applicationHost.config</code> defines settings specific to IIS only. You can review the <code>applicationHost.config</code> schema to confirm this:</p> <blockquote> <p><code>%systemroot%\System32\inetsrv\config\schema\IIS_schema.xml</code></p> </blockquote> <p>If you try to edit <code>applicationHost.config</code> and add an <code>&lt;appSetting&gt;</code> section to a site or under a <code>&lt;location path="..."&gt;</code> section you will get an error (IIS may not start and IIS MMC console will display a configuration error).</p> <p>If you configure a global application setting in IIS manager this actually gets configured in the master <code>web.config</code> file that matches the default .NET Framework version setting in IIS.</p> <p><code>&lt;appSettings/&gt;</code> is specific to the .NET Framework and can only be configured in:</p> <pre> %SYSTEMROOT%\Microsoft.NET\Framework\[framework version]\CONFIG\machine.config %SYSTEMROOT%\Microsoft.NET\Framework\[framework version]\CONFIG\web.config %SYSTEMROOT%\Microsoft.NET\Framework64\[framework version]\CONFIG\machine.config %SYSTEMROOT%\Microsoft.NET\Framework64\[framework version]\CONFIG\web.config </pre> <p>and of course your application's <code>app.config</code> or <code>web.config</code> files.</p> <p>My advice would be to keep these settings local to your application unless there is the rare occasion where you need some value to be available globally.</p> <p><em>Update:</em></p> <p>Now that I understand your problem - you have multiple IIS sites which all point to the same physical folder - there is a way to approach this.</p> <p>You could have a configuration table in your database that has a primary key of whatever the <code>HTTP_HOST</code> value is. This maps to a prefix, for example:</p> <pre> Host SitePrefix ==== ====== domain1.com D001 domain2.com D002 </pre> <p>In your <code>web.config</code>:</p> <p> </p> <p>In your application's <code>Application_Start</code> event in <code>Global.asax.cs</code> initialise an application wide value:</p> <pre><code>void Application_Start(object sender, EventArgs e) { // Code that runs on application startup string httpHost = HttpContext.Current.Request.ServerVariables["HTTP_HOST"]; Application["SitePrefix"] = GetSiteKeyFromDb(httpHost); } </code></pre> <p>This value will be available across the whole application but unique to the site.</p> <p>When you need to read a setting that is specific to the site:</p> <pre><code>string siteSetting = ConfigurationManager.AppSettings[ HttpContext.Current.Application["SitePrefix"] + "_Setting1" ]; </code></pre> <p>But if you're hitting the database in <code>Application_Start</code> then it may actually be expedient to store all these site specific settings in the database then read and cache them in <code>Application</code> instead of using <code>&lt;appSettings /&gt;</code>.</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