删除 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>
Run Code Online (Sandbox Code Playgroud)
导航到 /trace.axd 现在给我们一个 404 Not Found 而不是 500 Internal Server Error。
我首先想到的是拦截BeginRequest事件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, "");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
971 次 |
| 最近记录: |