views:

145

answers:

1

I have an ASP.NET web app and am attempting to reference an external config (using enterprise application blocks configuration) for some of the configuration but it is not entirely working.

I previously had all of the configuration info in the web.config (and it was working), but we are wanting to share some of this configuration information between multiple apps. When I put configurationSource tag in the web.config, and read the configuration through the WebConfigurationManager object, it loads some of the external config info (Logging) but not the connectionStrings and not the custom section I created. So it's reading it (logging is working), but some dots aren't being connected and my connection strings aren't coming through.

Again, it worked when it was all in the web.config. I am running .NET 3.5.

Any idea what needs to change to be able to reference an external configuration source and have it all come through?

[Code that accesses web.config]

Configuration webConfig =
    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
ConnectionStringSettingsCollection connectionStrings =
    System.Web.Configuration.WebConfigurationManager.ConnectionStrings;

[web.config]

<configuration>
  <configSections>
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=74025d8738dfe4ce" />
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
  </configSections>
  <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source">
    <sources>
      <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=74025d8738dfe4ce"
           filePath="C:\MSEAB\MSEAB.config" />
    </sources>
  </enterpriseLibrary.ConfigurationSource>
  ...
  ...
</configuration>

[external MSEAB.config]

<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=74025d8738dfe4ce" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=74025d8738dfe4ce" />
    <sectionGroup name="customSectionGroup">
      <section name="customSection" type="app.CustomSection" allowLocation="true" allowDefinition="Everywhere" />
    </sectionGroup>
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    ...
  </loggingConfiguration>

  <connectionStrings>
    <clear />
    <add name="DB.DEV" connectionString="User ID=user;Password=pwd;Data Source=DV1;" providerName="Oracle.DataAccess.Client"/>
    <add name="DB.TEST" connectionString="User ID=user;Password=pwd;Data Source=TS1;" providerName="Oracle.DataAccess.Client"/>
    ...
  </connectionStrings>
  <customSectionGroup>
    <customSection notificationemail="[email protected]" dirPath="C:\Dir" initialrowlimit="500" maxrowlimit="1500" adminadgroup="_admins">
    </customSection>
  </customSectionGroup>
</configuration>
A: 

Is the configuration Xml well formed? I encountered a problem with a Wcf configuration section the other day that I hadn't closed a tag properly, yet there were no obvious errors other than the services not responding.

Have you considered using the native externalising behaviour of the System.Configuration.SectionInformation.ConfigSource property? It's usage is the following:

<pages configSource="pages.config"/>

See the SectionInformation.ConfigSource topic for more information.

It should be noted that, due to security concerns, it supports only relative path names. Oh, and it can only be applied to a ConfigurationSection, not a ConfigurationElement.

Rabid