1

So I'm trying to add a 'ServerType' AppSetting. It works when I add it to a web.config.

web.config before:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  ...

web.config after:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="ServerType" value="I AM A WEB.CONFIG OVERRIDING MACHINE.CONFIG" />
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  ...

But I'm trying to do the same thing for the machine.config and it keeps throwing 500 errors.

machine.config before:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <configSections>
        <section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=blahblah" restartOnExternalChanges="false" requirePermission="false" />
        ...

Attempt 1:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <configSections>
        <section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=blahblah" restartOnExternalChanges="false" requirePermission="false" serverType="I AM MACHINE" />
        ...

Result:

The page cannot be displayed because an internal server error has occurred.

Attempt 2:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <configSections>
        <section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=blahblah" restartOnExternalChanges="false" requirePermission="false">
            <add key="ServerType" value="I AM MACHINE" />
        </section>
        ...

Result:

Runtime Error

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

(Which is odd because the web.config already has <customErrors mode="Off"></customErrors>.)

Attempt 3:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <configSections>
        <appSettings>
        <add key="ServerType" value="I AM MACHINE" />
    </appSettings>
        <section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=blahblah" restartOnExternalChanges="false" requirePermission="false"/>
        ...

Result:

The page cannot be displayed because an internal server error has occurred.

I'm clearly missing something fundamental here, but I haven't been able to figure out nor research what.

Sarov
  • 545
  • 6
  • 17

1 Answers1

2

That appSettings element needs to be added after the configSections element.

machine.config:

<configuration>
    <configSections>
        <section name="appSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
        <!-- More section definitions ... -->         
    </configSections>
    
    <appSettings>
        <add key="ServerType" value="I AM MACHINE" />
    </appSettings>
    
    <!-- More sections ... -->  
  
</configuration>
pfx
  • 20,323
  • 43
  • 37
  • 57
  • ...Hm. Trying that gives me a different error - `HTTP Error 503. The service is unavailable.` – Sarov Aug 26 '22 at 19:44
  • You did keep everything as-is, just adding that ...? – pfx Aug 26 '22 at 19:52
  • Yeah. ...Though it's still giving that even when I put the machine.config back the way it was, and even when I deleted the entire app. I think something's wrong with the server itself, now. I'll try again after I get the admin to fix the server. – Sarov Aug 26 '22 at 19:53
  • I verified that above setup is working "on my machine" ;) – pfx Aug 26 '22 at 19:55
  • Haha. Well, time to hurry up and wait... I'll reply once the server's fixed. – Sarov Aug 26 '22 at 20:07
  • 1
    Apparently "the application pool crashed due to a bad config." So after restarting the IIS application pool, it works now. Thanks! – Sarov Sep 01 '22 at 15:47