企业库在ASP.NET应用程序中无法找到配置源文件

4
我将我的配置文件放在基础目录中,设置为Content/copy always,在我的asp.net web项目中,当应用程序运行时,它会显示找不到文件。
<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>


你是否检查过文件是否实际位于预期位置? - NotMe
2个回答

2
我猜你收到了类似于这样的消息:System.IO.FileNotFoundException: 找不到配置文件cache.config。
从你的配置中,我可以看到你正在使用Enterprise Library 5.0(Build 414)。在该版本中,ASP.NET中相对路径和FileConfigurationSource存在问题Microsoft Enterprise Library 5.0 Optional Update 1(版本505)已经修复了这个问题,所以如果你使用最新版本,问题应该会得到解决。
或者,你可以更改配置文件以使用绝对路径。另一个解决方法是创建自己的FileConfigurationSource,正确解析路径。你可以在问题报告的注释中找到源代码。

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

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

1
因为它在子目录中 - Kayode Leonard
@Kayode Leonard:非常抱歉。在您的帖子中,您说“我将我的配置文件放在基本目录中,并设置为Content/copy always”。不清楚AutomatorConsoleFileFullLogging.config如何到达“Logging Conifigs”目录。因此,我做出了回应。 - Sarin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接