asp.net - 避免 ASP.NET 子应用程序中继承的 ELMAH 错误

标签 asp.net elmah web-config

我有一个使用 ELMAH 的父 IIS 应用程序和一个不使用 ELMAH 的子 ASP.NET 应用程序(虚拟目录)。当我尝试浏览我的子应用程序时,出现此错误:

Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.

这是可以理解的,因为我的 child 应用程序的 bin文件夹不包含任何 ELMAH 程序集。

问题可能是父 web.config文件包含以下内容:

  <configSections>      
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup>
  </configSections>

据我了解,没有办法阻止 <configSections>继承,参见例如How to stop inheritance of <configSections>in Web.Config 。那么有没有办法运行我的无 ELMAH 子应用程序?

最佳答案

由于父配置的原因,您无法使子应用程序保持无 ELMAH。但是 - 因为我想你不想引用父级的程序集 - 你可以做的就是告诉你的子应用程序 look for assemblies in the parent bin folder使用探测配置。

这样,您的子应用程序不需要知道父应用程序存在哪些程序集,只需知道如果需要未知程序集,可以在父文件夹中找到它

<小时/>

编辑:这确实是一个无赖。 Clearing and removing configsections tags was considered too complex by Microsoft :

<clear /> and <remove /> were never implemented for configSections and sectionGroups because of the difficulty involved attempting to merge different definitions of the same section-handlers and section groups.

因此就有了路径解决方法。如果这很重要,您还可以设置应用程序,使它们在层次结构方面不相关

关于asp.net - 避免 ASP.NET 子应用程序中继承的 ELMAH 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25504431/

相关文章:

c# - Web Config 转换问题

asp.net - web.config 中的加密连接字符串

asp.net - Security.Authentication.AuthenticationException : The remote certificate is invalid according to the validation procedure

c# - 使用 Javascript 更改 HiddenField 值不会在 C# 代码隐藏中更改

javascript - 无论给定变量的值如何,都使用相同的 javascript if 条件

asp.net - 对所有 ASP.NET MVC 错误使用全局(哑)错误页面?

elmah - 城堡单轨铁路和 ELMAH

asp.net - 如何在 .NET 3.5 中使用 System.IdentityModel.Tokens.Jwt 5.2.1?

asp.net - ELMAH:ASP.NET 安全

wcf - 将WCF服务部署到SharePoint 2010网站时出现“找不到端点”错误