我的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>

最佳答案

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

关于c# - 如何在MVC3中获取trace.axd的自定义错误页面?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11724771/

10-14 03:20