0

I am using asp.net MVC5 I created a custom error page under Views/shared/Error.cshtml I updated the web.config with the following;

<customErrors mode="On" defaultRedirect="~/Shared/Error.cshtml" />

I also created an error controller class under Controllers as follows;

`public class ErrorController : Controller
{
    // GET: Error
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Error()
    {
        return View();
    }
}`

when I run the application and put invalid URL I do not get my custom error page that i created, i still get the common system error page. what could be cause for not showing it? ... thank you.

1

1 Answer 1

1

you need to define your error page in web config

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

here's the controller

public class ErrorController : Controller
{
    public ViewResult Index()
    {
        return View("Error");
    }
    public ViewResult NotFound()
    {
        Response.StatusCode = 404;
        return View();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.