我有一个使用 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/