1

I'm trying to execute my custom error controller action when a user tries to visit a non-existing URL. I've added this:

<httpErrors errorMode="Custom" existingResponse="PassThrough">
      <remove statusCode="404"/>
      <error statusCode="404" path="error/404-not-found" responseMode="ExecuteURL"/>
</httpErrors>

I also have a controller for errors, and I confirm that /error/404-not-found is accessible (I see the correct error page). However, when I try to visit a non-existent URL, I'm still getting the regular "Server error in / Application" 404 error instead of my custom error page. I've also tried different existingResponse and responseMode values but no avail. How do I get my 404 errors redirect to my page?

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • Have you tried using `redirect`? ``. Have a look at to [this answer](http://stackoverflow.com/a/7442327/1380428). – Adil Mammadov Sep 08 '16 at 06:51
  • @AdilMammadov having used ASP.NET MVC for several years now, and I've just realized there are two different error handling mechanisms in web.config: httpErrors and customErrors. Terrible design decision at Microsoft's side. Anyway, using custom errors fixed the issue for me. – Can Poyrazoğlu Sep 08 '16 at 07:04
  • I am glad that it helped.You can also refer to [this answer](http://stackoverflow.com/a/2481102/1380428) for differences between *httpErrors* and *customErrors*. Be sure to read comments also. Thank you too. – Adil Mammadov Sep 08 '16 at 07:07

0 Answers0