File Configuration Source from Virtual Directory

Topics: General discussion, Logging Application Block
Aug 13, 2008 at 11:27 AM
Hello,

i have a File Configuration Source key in my web.config file and i would like that the location of the config file can be readed  from a Virtual Path in place than a Phisical Path, is this possible?

This is the key in my web.config

<add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath="C:\Workspaces\Configuration\enterpriseLibrary.logging.config" />

and this is how i would like (or think) that it can be (?):

<add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath="/MyViritualPath/Configuration/enterpriseLibrary.logging.config" />
Aug 13, 2008 at 2:36 PM
Hi,

It's not possible to open a file from a virtual directory. EntLib relies on the .NET framework's ConfigurationManager class to open arbitrary configuration files with the FileConfigurationSource, and only file system references are supported.

There is a parallel API implemented by the WebConfigurationManager, which might be used to support a new configuration source that works the way you need.

Fernando
Aug 13, 2008 at 3:00 PM
Thanks!

can you tell me please how to implement the WebConfigurationManger?
Aug 13, 2008 at 4:32 PM
Hi,

First a disclaimer: I haven't tried this so it may not work. Having said that, the WebConfigurationManager class is part of the .NET framework and provides some methods equivalent to the ones from the ConfigurationManager class used to implement the FileConfigurationSource. You can copy the the implementation of the FileConfigurationSource and replace the calls to ConfigurationManager with calls to WebConfigurationManager. Beware, the FileConfigurationSource is complicated, but mostly because of the support for reacting to changes in the configuration file which may not be necessary in your web scenario.

Feranndo