I want a custom error page shown for 500, 404 and 403. Here\'s what I have done:
Enabled custom errors in the web.config as follows:
There seem to be a number of steps here jumbled together. I'll put forward what I did from scratch.
Create the ErrorPage
controller
public class ErrorPageController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Oops(int id)
{
Response.StatusCode = id;
return View();
}
}
Add views for these two actions (right click -> Add View). These should appear in a folder called ErrorPage.
Inside App_Start
open up FilterConfig.cs
and comment out the error handling filter.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// Remove this filter because we want to handle errors ourselves via the ErrorPage controller
//filters.Add(new HandleErrorAttribute());
}
Inside web.config add the following
entries, under System.Web
Test (of course). Throw an unhandled exception in your code and see it go to the page with id 500, and then use a URL to a page that does not exist to see 404.