我的配置文件在基本目录中,在我的asp .net web项目中始终设置为Content / copy,当应用程序运行时,它说无法找到文件.
<enterpriseLibrary.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=null" />
<!--<add name="Logging File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
filePath="AutomatorConsoleFileFullLogging.config" />-->
<add name="Logging File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
filePath="Logging Configs\AutomatorConsoleFileFullLogging.config" />
<add name="Exception Handling Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
filePath="ExceptionHandling.config" />
<add name="Policy Injection Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
filePath="PolicyInjection.config" />
</sources>
<redirectSections>
<add sourceName="Exception Handling Source" name="exceptionHandling" />
<add sourceName="Logging File Source" name="loggingConfiguration" />
<add sourceName="Policy Injection Configuration Source" name="Policy Injection Settings" />
</redirectSections>
最佳答案 我假设您收到类似于以下消息:System.IO.FileNotFoundException:找不到配置文件cache.config.
从您的配置中我可以看到您正在使用Enterprise Library 5.0(Build 414).该版本中有一个issue,其中包含ASP.NET中的相对路径和FileConfigurationSource.
Microsoft Enterprise Library 5.0 Optional Update 1(build 505)已修复此问题,因此如果您使用最新版本,则应解决该问题.
或者您可以更改配置文件以使用绝对路径.另一个修复方法是创建自己的FileConfigurationSource,以正确解析路径.您可以在comments of the issue report找到来源.