Alex Rivera | Logout

applicationSettings and Web.config

Asked 2010-05-25T16:14:13.927
24

I have a DLL that provides logging that I use for WebForms projects and now wish to use it in an ASP.Net MVC 2 project.

Some aspects of that DLL are configured in app.config:

<configuration>
    <configSections>
            <section name="Tools.Instrumentation.Properties.Settings" 
                     type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                     requirePermission="false" />
        </sectionGroup>
    </configSections>

 <applicationSettings>
        <Tools.Instrumentation.Properties.Settings>
            <setting name="LogLevel" serializeAs="String">
                <value>DEBUG</value>
            </setting>
            <setting name="AppName" serializeAs="String">
                <value>MyApp</value>
            </setting>
            <setting name="Port" serializeAs="String">
                <!--value>33333</value-->
                <value>0</value>
            </setting>
        </Tools.Instrumentation.Properties.Settings>
    </configuration>    

However, when I create a similar entry in Web.config, I get the error:

Unrecognized configuration section applicationSettings

My two-part question:

  • How do I make this config entry work in Web.config?
  • Where can I read up on the conceptual differences between WinForms configuration and ASP.Net configuration?
Edit
Report

1 Answer

64

Your config file was just missing the applicationSettings section group:

<configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="Tools.Instrumentation.Properties.Settings" 
                 type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                 requirePermission="false" />
    </sectionGroup>
</configSections>

If you add that, you can put your Settings section inside the tag and your assembly should read from it as normal.

answered 2010-11-03T19:03:34.307

Your Answer