Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

applicationSettings and Web.config

Tags:

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?
like image 449
Eric J. Avatar asked May 25 '10 16:05

Eric J.


People also ask

What is app settings in web config?

The <appSettings> element of a web. config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work.

What is the use of app config or web config in C#?

By adding an application configuration file (app. config file) to a C# project, you can customize how the common language runtime locates and loads assembly files. For more information about application configuration files, see How the runtime locates assemblies (. NET Framework).

Where is Web config configuration file?

The Web. Config file is used to configure Oracle Web Application functionality. This file is typically installed in the c:\Inetput\wwwroot\WebApp directory.

What is Web config in asp net?

web. config file is an XML-based configuration file used in ASP. NET-based applications to manage various settings that are concerned with the configuration of our website. In this way, we can separate our application logic from configuration logic.


2 Answers

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.

like image 159
xr280xr Avatar answered Sep 23 '22 01:09

xr280xr


Here's the .NET 4 version of the missing configuration:

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

Make sure to update the namespace of the <section>'s name attribute value to match your own.

like image 34
Sam Avatar answered Sep 19 '22 01:09

Sam