This happens because the default route (assuming you have one) will still match to Elmah.Mvc.ElmahController.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
The "{controller}" portion of the route will find a matching controller whether you want it to or not. This is obviously problematic in this case.
You can add constraints on your routes by using IRouteConstraint, outlined here. The NotEqual constraint is actually pretty 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 then exclude ElmahController from the default route by 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 make requests for "/elmah" return a 404.