> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/asp-net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/asp-net/chapter1/1.1.the-complete-asp.net-mvc-5-course/111deployment/1115custom-error-pages.md).

# 1.11.5.Custom Error Pages

* 1.Try to throw an exception

  ```
   public ActionResult About()
        {
            throw new Exception();

            return View();
        }
  ```
* 2.Edit web.config

  * RemoteOnly: when running on local site, it will turn off&#x20;

  ```
  <system.web>
    <!--<customErrors mode="RemoteOnly"></customErrors>-->
    <customErrors mode="On">
      <error statusCode="404" redirect="~/404.html"/>
    </customErrors>
  ```
* 3.Add 404.html

  ```
  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8" />
    <title></title>
  </head>
  <body>
  <h1>Not found</h1>
  </body>
  </html>
  ```
* 4.Edit web.config

  ```
  <system.webServer>
    <httpErrors errorMode="Custom">
      <remove statusCode="404"/>
      <error statusCode="404" path="404.html" responseMode="File"/>
    </httpErrors>
  ```
