これは、デフォルト ルート (ルートがあると仮定) がまだ Elmah.Mvc.ElmahController に一致するために発生します。
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
ルートの「{controller}」部分は、必要かどうかに関係なく、一致するコントローラーを見つけます。この場合、これは明らかに問題です。
こちらで概説されている IRouteConstraint を使用して、ルートに制約を追加できます。NotEqual 制約は、実際には非常に便利です。
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;
}
}
したがって、次を使用して、デフォルト ルートから ElmahController を除外します。
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = new NotEqual("Elmah") });
これにより、「/elmah」のリクエストで 404 が返されます。