【发布时间】:2011-03-14 00:28:57
【问题描述】:
我们正在运行 IIS7 和 .net 4.0。当服务器由于长时间运行的请求而超时时,会显示错误页面,但错误代码只是 500 而不是我期望的 408 或可能的 503。如果超时,我们想显示一个不同的错误页面,但如果它只是给出 500 错误,我无法在 <customErrors> 部分中配置它。这是配置问题吗?
【问题讨论】:
标签: iis httpexception request-timed-out
我们正在运行 IIS7 和 .net 4.0。当服务器由于长时间运行的请求而超时时,会显示错误页面,但错误代码只是 500 而不是我期望的 408 或可能的 503。如果超时,我们想显示一个不同的错误页面,但如果它只是给出 500 错误,我无法在 <customErrors> 部分中配置它。这是配置问题吗?
【问题讨论】:
标签: iis httpexception request-timed-out
您可以将这样的代码添加到您的 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 只是传递它。
【讨论】: