我们正在运行 IIS7 和 .net 4.0。当服务器由于长时间运行的请求而超时时,会显示错误页面,但错误代码只是 500 而不是我期望的 408 或可能的 503。<customErrors>
如果超时,我们想显示一个不同的错误页面,但如果它只是给出 500 错误,我无法在该部分中配置它。这是配置问题吗?
2002 次
1 回答
2
您可以将这样的代码添加到 global.asax.cs
public class Global : System.Web.HttpApplication
{
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex = HttpContext.Current.Server.GetLastError();
if (ex != null && ex is HttpException && ex.Message == "Request timed out.")
{
HttpContext.Current.Response.StatusCode = 503;
HttpContext.Current.Response.End();
}
}
}
我发现这无法正常工作,并且在没有 Response.End() 的情况下仍然返回 500 错误。鉴于您的问题,我不确定您是否要进行重定向以显示一个错误页面,该页面本身会输出 503 而不是上面的。
它真的是 ASP.NET 返回 500 状态,IIS 只是传递它。
于 2011-03-18T23:51:46.077 回答