1

I have developed an MVC5 page and have this in web.config:

<customErrors mode="On" defaultRedirect="/Home/Error" />

the problem is that this only works when I enter a non existing file in URL, for example, "/images/nonexisting". However, when I enter just "/images/" in URL (this folder does exist), an

"Error HTTP 403.14 - Forbidden"

is shown instead of custom error page.

How can I solve this?

EDIT: this is not duplicated. Referenced page is about defaultRedirect not taking into account at all. In my case, it works but only for 404 errors. For 403.14 errors, it does not work.

One other fact took my attention.

When I placed mode=Off in customErrors tag, and tried to load "/images/nonexisting", I get this error:

enter image description here

However, when I tried to load /images/, I got the following page:

enter image description here

As you see, both pages have different look. I think that is why it does not work, but I am not sure how to solve it.

It seems 404 errors are trapped by .NET Framework but 403 errors are trapped by the Web server not actually reaching the web site (that may be why custom error page is not shown). The only solution to this should be to try to configure this directly in the web Server?

Furthermore, I tried adding this to web.config, but it did not work either:

<customErrors mode="On" defaultRedirect="~/Home/Error">
  <error statusCode="403" redirect="~/Home/Error" />
</customErrors>
jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • Possible duplicate of [ASP.NET MVC4 CustomErrors DefaultRedirect Ignored](https://stackoverflow.com/questions/17636806/asp-net-mvc4-customerrors-defaultredirect-ignored) – Rob Anthony Sep 12 '17 at 14:33
  • This is not duplicate. Please review my EDIT in the question. – jstuardo Sep 12 '17 at 14:50
  • It seems 404 error is trapped by the .NET Framework, but 403 error is by the Web Server so the request never reaches the web site. – jstuardo Sep 12 '17 at 14:52
  • Yes. It works for 404 errors but doesn't work for others. – Rob Anthony Sep 12 '17 at 15:04
  • A request might go IIS->ASP.NET MVC, where your `customErrors` setting applies. But it can also go only IIS, and not ASP.NET MVC. So the issue cannot be "solved" in the way you like, and you need to configure custom errors at both IIS and ASP.NET leve. Please refer to posts such as https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging for more technical details. – Lex Li Sep 26 '17 at 16:35
  • Yes.. I have solved the problem that way. I have configured error pages redirect in IIS Console – jstuardo Sep 26 '17 at 18:39

0 Answers0