0

Can someone explain why my custom error pages in MVC with windows authentication work when I access http://localhost:port/controler/blabla/blabla, but when I try to access http://localhost:port/controler/action/blabla/blabla, it doesn't invoke my custom 404 page but displays a blank window.

For example, when I call http://localhost:port/Home/blabla/blabla, my custom page is called; but when I call http://localhost:port/Home/Index/blabla/blabla (the same URL with action added), it shows the blank page. Is it something with my configuration?

My config:

 <customErrors mode="On" defaultRedirect="~/UnAuthorized/ErrorDefault/?error=1">
  <error statusCode="404" redirect="~/UnAuthorized/ErrorResourceNotFound/?error=1"/>
  <error statusCode="403" redirect="~/UnAuthorized/ErrorResourceNotFound/?error=1"/>
  <error statusCode="500" redirect="~/UnAuthorized/ErrorDefault/?error=1"/>
</customErrors>

 <httpErrors errorMode="Custom">
  <remove statusCode="404" subStatusCode="-1"/>
  <remove statusCode="403" subStatusCode="-1"/>
  <remove statusCode="500" subStatusCode="-1"/>
  <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="~/UnAuthorized/ErrorResourceNotFound/?error=1" responseMode="ExecuteURL" />
  <error statusCode="403" subStatusCode="-1" path="~/UnAuthorized/ErrorResourceNotFound/?error=1" responseMode="ExecuteURL" />
  <error statusCode="500" subStatusCode="-1" path="~/UnAuthorized/TestPage" responseMode="ExecuteURL" />
</httpErrors>
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Gamaboy
  • 117
  • 11
  • I'd say `http://localhost:port/Home/blabla/blabla` will try to invoke `HomeController.blabla(blabla)`, where the `blabla` action doesn't exist (and therefore redirect to 404), and `http://localhost:port/Home/Index/blabla will invoke `HomeController.Index(blabla)`, where the `Index` action exists. – gobes May 05 '17 at 11:58
  • possible duplicate of http://stackoverflow.com/questions/310580/how-can-i-make-a-catch-all-route-to-handle-404-page-not-found-queries-for-asp – Biby Augustine May 05 '17 at 12:08

1 Answers1

0

Use redirect mode as "ResponseRedirect" in custom error tag like

<customErrors mode="On" defaultRedirect="~/UnAuthorized/ErrorDefault/?error=1" redirectMode="ResponseRedirect">
    <error statusCode="404" redirect="~/UnAuthorized/ErrorResourceNotFound/?error=1" />
<error statusCode="403" redirect="~/UnAuthorized/ErrorResourceNotFound/?error=1"/>
  <error statusCode="500" redirect="~/UnAuthorized/ErrorDefault/?error=1"/>
 </customErrors>
Biby Augustine
  • 425
  • 1
  • 3
  • 16