Show custom error for “504 Gateway Timeout error”

大憨熊 提交于 2019-12-04 19:10:19

If your ASP.NET MVC application is hosted by the IIS (or another proxy server), then the 504 error is returned by the IIS and sent to the browser, because your application does not respond to the request in a timely manner. The IIS has got a timeout (configurable for each web site) and if this is reached, then 504 is returned.

In this scenario you cannot define a custom error page inside your application, because it is not reacting.

You can configure the IIS to server custom error pages. This video tutorial shows how to do this.

Andrew Diamond

ASP doesn't actually return those pages, that's actually IIS.

Check out this SO on configuring IIS to let you return custom error pages


Basically you'll need to configure these settings:

<system.web>
    <customErrors mode="On" defaultRedirect="~/Error">
      <!--Use whatever paths you need here, along with the accompanying status code -->
      <error redirect="~/Error/NotFound" statusCode="404" />
    </customErrors>
</system.web>

And create a controller to handle the errors, like so:

public class ErrorController : Controller
{
    public ViewResult Index()
    {
        return View();
    }
    public ViewResult NotFound()
    {
        Response.StatusCode = 404;  
        return View();
    }
}

Along with whatever view you need to match the Action.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!