0

I want to show a custom page if the user tries to go a controller that does not exist. I've tried the method where you have to create the page you want to show in case of an error and turn on custom errors. But for some reason it doesn't work. This is what I've tried so far.

Web.config
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Views/Shared/Error/">
   <error statusCode="404" redirect="~/Views/Shared/Error/Index/" />
</customErrors>

<httpErrors errorMode="DetailedLocalOnly">
      <remove statusCode="404"/>
      <error statusCode="404" path="~/Views/Shared/Error.cshtml" responseMode="File"/>
</httpErrors>

ErrorController

public class ErrorController : Controller
    {
        //
        // GET: /Error/

        public ActionResult Index()
        {
            Response.StatusCode = 404;
            Response.TrySkipIisCustomErrors = true;
            return View();
        }
    }

Any help is appreciate it. I've searched a bunch of websites, and most explained that this is how it's done. I'm still new with this, so perhaps I'm missing the whole point.

Rocshy
  • 3,391
  • 11
  • 39
  • 56

1 Answers1

0

You are having it go to the view (the razor file), not to the controller on the route.

Perhaps you want /Error?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445