如何在MVC3中获取trace.axd的自定义错误页面?

时间:2012-07-30 15:39:13

标签: c# asp.net-mvc-3 trace custom-error-pages axd

我的MVC3应用程序显示403,404和500状态代码的自定义错误页面,但浏览到trace.axd会显示以下YSOD:

    Server Error in '/' Application.

    Trace Error

    Description: Trace.axd is not enabled in the configuration file for this application. Note: Trace is never enabled when <deployment retail=true /> 

    Details: To enable trace.axd, please create a <trace> tag within the configuration file located in the root directory of the current web application. This <trace> tag should then have its "enabled" attribute set to "true".

    <configuration>
         <system.web>
            <trace enabled="true"/>
        </system.web>
    </configuration>

所以我禁用了跟踪,这很好,但为什么500页面没有显示,因为这是从服务器返回的403?我真的很满意404,403或500 - 只要它不是一个丑陋的黄色屏幕!

编辑:当我在localhost上运行时,我和YSOD一起获得了500,但它实际上是服务器上的403,更接近我的期望 - 但仍然没有自定义错误页面。它也是服务器上稍微不同的标准错误页面:

Server Error in '/' Application.

Trace Error

Description: The current trace settings prevent trace.axd from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable trace.axd to be viewable on remote machines, please create a <trace> tag within the configuration file located in the root directory of the current web application. This <trace> tag should then have its "localOnly" attribute set to "false".

<configuration>
    <system.web>
        <trace localOnly="false"/>
    </system.web>
</configuration>

2 个答案:

答案 0 :(得分:1)

由于没有回复,我在Twitter上询问@shanselman,谁建议<deployment retail = "true" />可以解决它,但它仍然返回相同的YSOD。

最后我通过删除routes解决了它.IgnoreRoute(“{resource} .axd / {* pathInfo}”);来自路由配置。看起来不太对劲,但确实有效。

答案 1 :(得分:1)

按照@Cosmologinaut的建议删除IgnoreRoute并不适合我,因为他觉得错了。我找到了一个更好的解决方案,即删除Web.config文件中的跟踪HTTP处理程序:

  <system.webServer>
    <!-- remove TraceHandler-Integrated - Remove the tracing handlers so that navigating to /trace.axd gives us a 
         404 Not Found instead of 500 Internal Server Error. -->
    <handlers>
      <remove name="TraceHandler-Integrated" />
      <remove name="TraceHandler-Integrated-4.0" />
    </handlers>
  </system.webServer>

导航到/trace.axd现在为我们提供了404 Not Found而不是500 Internal Server Error。