In my ASP.Net MVC2, how do I create a wide 404 page?
Meaning every single time someone tries to enter a non-existent view/page, he's redirected to this error page of my choosing?
In my ASP.Net MVC2, how do I create a wide 404 page?
Meaning every single time someone tries to enter a non-existent view/page, he's redirected to this error page of my choosing?
Use the standard ASP.NET error pages (activate in web.config):
<customErrors mode="On|RemoteOnly" defaultRedirect="/error/problem">
<error statusCode="404" redirect="/error/notfound"/>
<error statusCode="500" redirect="/error/problem"/>
</customErrors>
And/or create an error handling controller and use it with a catchall route:
ErrorController.cs:
public class ErrorController : Controller
{
public ActionResult NotFound(string aspxerrorpath)
{
// probably you'd like to log the missing url. "aspxerrorpath" is automatically added to the query string when using standard ASP.NET custom errors
// _logger.Log(aspxerrorpath);
return View();
}
}
global.asax:
// This route catches all urls that do not match any of the previous routes.
// So if you registered the standard routes, somthing like "/foo/bar/baz" will
// match the "{controller}/{action}/{id}" route, even if no FooController exists
routes.MapRoute(
"Catchall",
"{*catchall}",
new { controller = "Error", action = "NotFound" }
);