asp.net - 企业库在 ASP.NET 应用程序中找不到配置源文件

标签 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>

最佳答案

我假设您收到类似以下内容的消息: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 中找到源代码.

关于asp.net - 企业库在 ASP.NET 应用程序中找不到配置源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9333215/

相关文章:

asp.net - 从 MVC 操作返回多个文件

c# - 使用 Process.Start() 启动 exe,发生奇怪的事情

vb.net - WCF 和验证应用程序 block : Impossible to customize error messages?

.net - 如何使用企业库日志记录到用户的 ApplicationData 文件夹?

.net - 格式化日志记录应用程序 block 的 SystemDiagnosticsTraceListenerData 监听器的日志记录

asp.net - 使asp.net按钮控件的 Angular 变圆

css - 为什么 Font-Size 和 CssClass 属性在 aspx 页面的 CheckBoxList 中不起作用?

c# - 序列化空引用对象

c# - 如何使用服务器端将数据发布到 MVC4 中的外部 URL

c# - .NET 图形数据库