This is because the default route (if you have one) will still match Elmah.Mvc.ElmahController.
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional });
Part of the "{controller}" route will find the appropriate controller, whether you want it or not. In this case, this is clearly problematic.
You can add restrictions to your routes using the IRouteConstraint, indicated here . The NotEqual restriction is actually very useful.
using System; using System.Web; using System.Web.Routing; public class NotEqual : IRouteConstraint { private string _match = String.Empty; public NotEqual(string match) { _match = match; } public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { return String.Compare(values[parameterName].ToString(), _match, true) != 0; } }
So, exclude the ElmahController from the default route using the following.
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new { controller = new NotEqual("Elmah") });
This will cause / elmah to return 404.
pdubs
source share