我在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 ConfigsAutomatorConsoleFileFullLogging.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)。该版本中存在ASP.NET中的相对路径和FileConfigurationSource问题。
Microsoft Enterprise Library 5.0可选更新1(内部版本505)已修复此问题,因此如果使用最新版本,则应解决此问题。
或者,您可以更改配置文件以使用绝对路径。另一个修复方法是创建自己的FileConfigurationSource,以正确解析路径。您可以在问题报告的评论中找到来源。
<!--<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 ConfigsAutomatorConsoleFileFullLogging.config" />
为什么?
取消注释第一个标记,注释第二个标记。我认为这应该解决你的问题?