企业库无法在asp.net应用程序中查找配置源文件

时间:2012-02-17 18:07:32

标签: asp.net .net enterprise-library

我的配置文件位于基本目录中,在我的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>

2 个答案:

答案 0 :(得分:2)

我假设您收到的消息类似于:System.IO.FileNotFoundException:找不到配置文件cache.config。

从您的配置中我可以看到您正在使用Enterprise Library 5.0(Build 414)。该版本中有一个issue,其中包含ASP.NET中的相对路径和FileConfigurationSource。

Microsoft Enterprise Library 5.0 Optional Update 1(版本505)修复了此问题,因此如果您使用最新版本,则应解决此问题。

或者您可以更改配置文件以使用绝对路径。另一个修复方法是创建自己的FileConfigurationSource,以正确解析路径。您可以在comments of the issue report

中找到来源

答案 1 :(得分:0)

  <!--<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" />

为什么?

取消注释第一个标记,注释第二个标记。我认为这应该解决你的问题?