Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a custom error page for trace.axd in MVC3?

My MVC3 application displays custom error pages for 403, 404, and 500 status codes, but browsing to trace.axd displays the following 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>

So I have trace disabled, which is good, but why is the 500 page not being displayed, since this it's a 403 being returned from the server? I'd be happy enough with a 404, 403, or 500 really - just as long as it's not an ugly yellow screen!

Edit: I was getting a 500 along with the YSOD when running on localhost, but it's actually a 403 on the server which is closer to what I was expecting - but still no custom error page. It's also a slightly different standard error page on the server:

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>
like image 316
Cosmologinaut Avatar asked Oct 08 '22 02:10

Cosmologinaut


2 Answers

Removing the IgnoreRoute as suggested by @Cosmologinaut didn't work for me and as he says feels wrong. I found a better solution which is to remove the tracing HTTP handler in the Web.config file:

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

Navigating to /trace.axd now gives us a 404 Not Found instead of 500 Internal Server Error.

like image 77
Muhammad Rehan Saeed Avatar answered Oct 13 '22 11:10

Muhammad Rehan Saeed


Since there were no responses I asked @shanselman on Twitter, who suggested <deployment retail = "true" /> might solve it, but it still returned the same YSOD.

In the end I solved it by removing routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); from the routing config. Doesn't quite seem right, but it works.

like image 41
Cosmologinaut Avatar answered Oct 13 '22 11:10

Cosmologinaut