Asp.net mvc ASP.NET MVC、HandleError属性和跟踪:Bug?

Asp.net mvc ASP.NET MVC、HandleError属性和跟踪:Bug?,asp.net-mvc,exception,exception-handling,trace,Asp.net Mvc,Exception,Exception Handling,Trace,在ASP.NET MVC应用程序中启用跟踪时,我似乎遇到了一些古怪的行为: 只要启用跟踪,HandleError属性就会失败 我在vanilla ASP.NET MVC应用程序上复制了这一点,我想知道是否有人经历过类似的事情 复制步骤 第一步 创建新的ASP.NET MVC应用程序 步骤2 在web.config中打开跟踪: <trace enabled="true" localOnly="false" pageOutput="false" requestLimit="500" trace

在ASP.NET MVC应用程序中启用跟踪时,我似乎遇到了一些古怪的行为:

只要启用跟踪,HandleError属性就会失败

我在vanilla ASP.NET MVC应用程序上复制了这一点,我想知道是否有人经历过类似的事情

复制步骤 第一步 创建新的ASP.NET MVC应用程序

步骤2 在
web.config
中打开跟踪:

<trace enabled="true" localOnly="false" pageOutput="false" requestLimit="500" traceMode="SortByTime" />
<!--<trace enabled="true" localOnly="false" pageOutput="false" requestLimit="500" traceMode="SortByTime" />-->
跟踪页面的工作原理是:

http://localhost/mvcapplication2/trace.axd
步骤4 在
HandleError
属性可以找到的地方模拟异常(控制器操作、视图)

我在
Home\Index.aspx
视图中抛出了一个异常:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="System.Threading"%>

<asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%= Html.Encode(ViewData["Message"]) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
        <% throw new NotImplementedException(); %>
    </p>
</asp:Content>
深入调查 步骤5 在
web.config
中禁用跟踪:

<trace enabled="true" localOnly="false" pageOutput="false" requestLimit="500" traceMode="SortByTime" />
<!--<trace enabled="true" localOnly="false" pageOutput="false" requestLimit="500" traceMode="SortByTime" />-->
(请注意,对于此跟踪,我的
HandleError
视图称为“InternalError.aspx”,而不是默认的“Error.aspx”)

缺陷 所以问题是,我是因为发现一只虫子而得到一块饼干,还是因为遗漏了一些明显的东西而被鳟鱼扇耳光


提前感谢您的帮助

作为后续行动:

这个问题仍然存在,但同时我已经实施了一个变通方法

我定义了一个自定义的
HandleError
属性,因为我正在插入ELMAH:

如何让ELMAH使用ASP.NET MVC[HandleError]属性?

OnException
方法的末尾,我简单地说:

filterContext.HttpContext.Trace.IsEnabled = false;
通过编程禁用对该请求的跟踪,我能够避免硬崩溃

由于异常无论如何都会被记录下来,我也不会因为关闭跟踪而失败。

+1详细问题(是的,我知道它已经存在2年了)
filterContext.HttpContext.Trace.IsEnabled = false;