# \[404 Page Not Found\] Error Handling

**URL:** <https://forum.dotvvm.com/t/404-page-not-found-error-handling/208>\
**Category:** Discussion in English\
**Created:** [May 24, 2024, 8:54pm UTC](https://forum.dotvvm.com/t/404-page-not-found-error-handling/208 "2024-05-24T20:54:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thatdbme](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/thatdbme/32/14_2.png) [@thatdbme](https://forum.dotvvm.com/u/thatdbme)\
**Post date:** [May 24, 2024, 8:54pm UTC](https://forum.dotvvm.com/t/404-page-not-found-error-handling/208/1 "2024-05-24T20:54:09Z")

</div>

I have an existing [ASP.Net](http://ASP.Net) application (not Core) with DotVVM being added to it. I have not been able to get the 404 error handling to work correctly.

I need to handle invalid page requests whether the request is for a DotVVM page (no extension) or an ASPX page or other extension.

Previous to adding DotVVM to the application, the following in the web.config worked.

```auto
<customErrors defaultRedirect="/Content/Errors/ErrorPage.aspx" mode="RemoteOnly" redirectMode="ResponseRewrite">
  <error statusCode="403" redirect="~/Content/Errors/UnauthorizedAccess.aspx" />
  <error statusCode="404" redirect="~/Content/Errors/PageNotFound.aspx" />
</customErrors>

```

After adding DotVVM to the application, the above no longer works, nor do any of the following.

```auto
<customErrors defaultRedirect="/Content/Errors/ErrorPage.aspx" mode="On" redirectMode="ResponseRewrite">
  <error statusCode="403" redirect="~/Content/Errors/UnauthorizedAccess.aspx" />
  <error statusCode="404" redirect="~/Errors/PageNotFound" />
</customErrors>

```

```auto
<customErrors mode="On" redirectMode="ResponseRewrite" >
    <error statusCode="404" redirect="/Errors/PageNotFound"/>
</customErrors>

```

**What is the proper way to handle a 404 Page Not Found error in an existing [ASP.Net](http://ASP.Net) (not Core) application?**

---

<div class="post-metadata">

**Author:** ![tomasherceg](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/tomasherceg/32/513_2.png) [@tomasherceg](https://forum.dotvvm.com/u/tomasherceg)\
**Post date:** [May 28, 2024, 4:46pm UTC](https://forum.dotvvm.com/t/404-page-not-found-error-handling/208/2 "2024-05-28T16:46:03Z")

</div>

It seems that you are using the old IIS `system.web/customErrors` section that was used in IIS 6 and very old versions of [ASP.NET](http://ASP.NET).

From IIS 7, there is the new `system.webServer/httpErrors` section that you need to use:

```auto
  <system.webServer>
      <httpErrors errorMode="Custom">
        <clear />
        <error statusCode="404" path="/Errors/PageNotFound" responseMode="ExecuteURL" />
      </httpErrors>
  </system.webServer>

```

---

<div class="post-metadata">

**Author:** ![thatdbme](https://forum.dotvvm.com/user_avatar/forum.dotvvm.com/thatdbme/32/14_2.png) [@thatdbme](https://forum.dotvvm.com/u/thatdbme)\
**Post date:** [June 10, 2024, 6:33pm UTC](https://forum.dotvvm.com/t/404-page-not-found-error-handling/208/3 "2024-06-10T18:33:21Z")

</div>

Thank you, Tomas, for the information.

You are correct, I am working on a very old application. When I looked to apply your suggestion I noticed that we already had that in place. I spent the better part of a week trying to get it to work with lots of different combinations.

Finally I discovered that it worked on the servers (but still not on my local machine) when I used our original config settings but removing `redirectMode="ResponseRewrite"` from the CustomErrors line.

I can’t explain it but it’s working for now. It appears that I must continue to use the old error pages until the conversion is completed.

Maybe this will be helpful to others.
