Custom 404 page that does not display when StatusCode is not 200

In my file web.config I have a custom error:

 <customErrors mode="On" defaultRedirect="~/Error"> <error redirect="~/Error/NotFound" statusCode="404" /> </customErrors> 

My NotFound action:

 public ActionResult NotFound() { Response.StatusCode = 404; //no issues when this is not set return View(); } 

Problem: This configuration works fine on the local server, but when I move it to the remote server, the custom 404 pages are not displayed (the default value is 404 IIS) if the NotFound action status code is set to 200.

Can someone explain what is happening?

+1
asp.net-mvc iis-7
source share
1 answer

You also want to disable IIS custom errors by setting TrySkipIisCustomErrors to true.

 public ActionResult NotFound() { Response.StatusCode = 404; Response.TrySkipIisCustomErrors = true; <--- return View(); } 
+4
source share

All Articles