Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get requests to trace.axd to return 404?

In my production environment, I would like to redirect all requests to /trace.axd to return HTTP 404. Currently, the default HTTP 500 is returning. This creates all sorts of unnecessary noise in our analytics tools. Environment is ASP.NET 4.0 web forms on IIS 7.5.

like image 518
Mark Richman Avatar asked Dec 31 '12 14:12

Mark Richman


2 Answers

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 74
Muhammad Rehan Saeed Avatar answered Oct 19 '22 12:10

Muhammad Rehan Saeed


First that comes to my mind is to intercept BeginRequest event in global.asax:

protected void Application_BeginRequest()
{
    // assuming that in your production environment debugging is off
    if (!HttpContext.Current.IsDebuggingEnabled && Request.RawUrl.Contains("trace.axd"))
    {
        HttpContext.Current.Response.StatusCode = 404;
        HttpContext.Current.Response.End();
        // or alternatively throw HttpException like this:
        // throw new HttpException(404, "");
    }
}
like image 2
Alexander Manekovskiy Avatar answered Oct 19 '22 14:10

Alexander Manekovskiy