Skip to content

Instantly share code, notes, and snippets.

<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
...
RouteTable.Routes.MapRoute(
"NotFound-Catch-All",
"{*any}",
new { controller = "NotFound", action = "NotFound" });
// To allow IIS to execute "/notfound" when requesting something which is disallowed,
// such as /bin or /app_data.
RouteTable.Routes.MapRoute(
"NotFound",
"notfound",
new { controller = "NotFound", action = "NotFound" });
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new {controller = "Home", action = "Index", id = UrlParameter.Optional});
<error statusCode="404" subStatusCode="8" path="404.htm" />
<system.web>
<!-- For IIS 5 and 6, and the Visual Studio Development Server -->
<httpHandlers>
<add path="*" verb="*"
type="MvcErrorHandling.MvcHelpers.CustomHttpNotFoundHandler"/>
</httpHandlers>
</system.web>
...
<system.web>
<httpRuntime relaxedUrlToFileSystemMapping="true"/>
...
return new HttpNotFoundResult();
throw new HttpException((int)HttpStatusCode.NotFound, "A message");
if (HttpRuntime.UsingIntegratedPipeline)
{
// TransferRequest approach.
}
else
{
// MvcHttpHandler approach.
}