Reputation: 33
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.
Upvotes: 0
Views: 47
Reputation: 764
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();
}
}
Upvotes: 1