Add following <customErrors>
tag in the web.config that helps you to redirect to the NotFound
action method of Error
controller if the system fails to find the requested url (status code 404) and redirects to ServerError
action method of error controller if the system fires an internal server error (status code 500)
<!--<Redirect to error page>-->
<customErrors mode="On" defaultRedirect="~/Error/ServerError">
<error redirect="~/Error/NotFound" statusCode="404" />
</customErrors>
<!--</Redirect to error page>-->
You have to create an Error
controller that contains ServerError
and NotFound
action method that renders the related view to display the proper message to the user.
public class ErrorController : Controller
{
public ActionResult NotFound()
{
return View();
}
public ActionResult Error()
{
return View();
}
}