Skip to content

Instantly share code, notes, and snippets.

public class SomeApplicationClass : HttpApplication
{
...
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new {controller="Home", action="Index", id=UrlParameter.Optional});
// More routes here.
<system.web>
<customErrors defaultRedirect="" />
<!-- any other elements -->
</system.web>
<customErrors defaultRedirect="~/path-to-your-error-page" />
<customErrors>
<error statusCode="500" redirect="~/path-to-your-error-page" />
</customErrors>
var exception = Server.GetLastError();
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" existingResponse="Auto" />
<!-- any other elements -->
</system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="500" />
<error
statusCode="500"
path="/MvcErrorHandling/Error/HttpErrors500"
responseMode="ExecuteURL" />
</httpErrors>
Response.TrySkipIisCustomErrors = true;
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}