0

I am trying to do a custom 404 page.

I added an ErrorController as follows

public class ErrorController : Controller
{
    public ViewResult PageNotFound()
    {
        Response.StatusCode = 404; 
        return View();
    }
}

Added a View folder Error in the following hierarchy: Views > Error > PageNotFound.cshtml - which has my custom 404 message.

In web.config file in the <system.web> tag:

<customErrors mode="On" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="~Views/Error/PageNotFound"/>
</customErrors>
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
cgeekmt
  • 63
  • 2
  • 12
  • similar : http://stackoverflow.com/questions/13905164/how-to-make-custom-error-pages-work-in-asp-net-mvc-4 –  Mar 15 '16 at 13:54

2 Answers2

0

I think the slash is missing after ~

<customErrors mode="On" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="~/Views/Error/PageNotFound"/>
</customErrors>
REDEVI_
  • 684
  • 8
  • 18
  • Tried it however now this error occured Server Error in '/' Application. Runtime Error Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated. – cgeekmt Mar 15 '16 at 12:14
  • If he's giving it the full path doesn't he also need the .cshtml or .htm or whatever file extension as well? – jleach Mar 15 '16 at 12:15
0

I think you should be redirecting to the controller action instead of the VIEW

<customErrors mode="On" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="~/Error/PageNotFound"/>
</customErrors>
REDEVI_
  • 684
  • 8
  • 18