5

我的 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 真的很满意——只要它不是丑陋的黄色屏幕!

编辑:在本地主机上运行时,我得到了 500 和 YSOD,但它实际上是服务器上的 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>
4

2 回答 2

3

按照@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。

于 2015-03-04T11:24:11.690 回答
1

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

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

于 2013-08-22T13:35:30.947 回答