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.
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.
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, "");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With