Can a web.config read from an external xml file?

Yes, any configuration section can be “externalized” – this includes things like <appSettings>, <connectionStrings> and many more.

You’d have something like this in your web.config:

<configuration>
   <appSettings configSource="appSettings.config" />   
   <connectionStrings configSource="connectionStrings.config" />
   <system.web>    
      <pages configSource="pages.config" />
      <httpHandlers configSource="httphandlers.config">
   </system.web>    
</configuration>

The externalized config’s would just contain that one subsection in them:

httphandlers.config:

<httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>

Note you cannot externalize the entire <system.web> part, since that is a configuration section group – not a configuration section – but you can externalize most of the sub-sections contained in system.web.

Leave a Comment