Enterprise Library 5: How to configure FileConfigurationSource relative to asp.net web application folder?
I have my validation configuration stored in validation.config in my Business Object project. The config file is set to copy if newer
The business object project is referenced by my web project, therefore, the validation.config copies to the bin folder of my web application.
In my web.config I have the validation configuration redirected:
<enter开发者_高级运维priseLibrary.ConfigurationSource selectedSource="System Configuration Source">
<sources>
<add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="ValidationConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
filePath="bin\validation.config" />
</sources>
<redirectSections>
<add sourceName="ValidationConfigurationSource" name="validation" />
</redirectSections>
However, using procmon I can see it is trying to load the configuration from C:\WINDOWS\system32\bin\validation.config
The source for the FileConfigurationSource doesn't seem to have anything in it about creating a path using AppDomain.CurrentDomain.BaseDirectory so I'm not sure how relative paths can work with asp.net
How can I get this to work for an ASP.NET application?
I am running on XP using the local IIS server launching in debug mode.
Edit
Sorry, just realized there are two open issues filed for this:
http://entlib.codeplex.com/workitem/26990
http://entlib.codeplex.com/workitem/26760
If I come up with a workaround, I will post here.
To fix the code in the Microsoft Enterprise Library source, replace the following method in FileConfigurationSource.cs with the code shown below. The modified code moves the check for file existence after the creation of a rooted file path.
private static string GetRootedCurrentConfigurationFile(string configurationFile)
{
if (string.IsNullOrEmpty(configurationFile))
throw new ArgumentException(Resources.ExceptionStringNullOrEmpty, "configurationFile");
string strPath =
Path.IsPathRooted(configurationFile)
? configurationFile
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configurationFile);
if (!File.Exists(strPath))
{
throw new FileNotFoundException(
string.Format(
CultureInfo.CurrentCulture,
Resources.ExceptionConfigurationLoadFileNotFound,
configurationFile));
}
return strPath;
}
精彩评论