In my Asp.Net MVC website, I'm trying to get the custom error page working. In the development machine, everything works. But when I publish the website to the production, it only works if I set the status code to 200 (or don't set it). Here's my web.config
:
<customErrors mode="On" defaultRedirect="~/Error" redirectMode="ResponseRedirect">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
And this is the ErrorController
public class ErrorController : Controller
{
public ViewResult Index()
{
return View("Error");
}
public ViewResult NotFound(string aspxerrorpath)
{
Response.StatusCode = 404; //if I comment out this line, it works
return View("NotFound");
}
}
If I comment out the code Response.StatusCode = 404;
the error page shows up. Otherwise it shows the default 404 page on the website. Again, this works on my development machine. Am I missing something? How can I render the custom error page AND return the 404 code at the same time?