既にいくつかのコントローラーを持つ MVC 4 アプリケーションに、新しいコントローラー "LoggingController" を追加しました。ここで、このコントローラーのルーティング動作が既存のものとは異なることに気付きました。
たとえば、次の 2 つの URL は期待どおりに正しく機能し、BlogController の "Index" メソッドにヒットします。
http://localhost:56933/Blog/
http://localhost:56933/Blog/Index
私が追加したものを除く他のすべてのコントローラーも同様です。
http://localhost:56933/Logging/Index
- 正常に動作し、LoggingController の「Index」メソッドにヒットします
http://localhost:56933/Logging/
- 「'/' アプリケーションでサーバー エラーが発生しました。リソースが見つかりません。」を返します。
当たり前のことを超えて、どこから見始めるべきですか?
LoggingController の Index シグネチャは次のとおりです。
public ActionResult Index(int? page, string Period, string LoggerProviderName, string LogLevel, int? PageSize)
MapRoute 内の特定のコントローラーに固有のものはありません。参照用の完全な RouteConfig は次のとおりです。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Display",
url: "Post/{id}/{seofriendly}",
defaults: new { controller = "Post", action = "Display", id = UrlParameter.Optional, seofriendly = ""}
);
routes.MapRoute(
name: "SEOFriendly",
url: "{controller}/{action}/{id}/{seofriendly}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, seofriendly = "" }
);
routes.MapRoute(
name: "SEOFriendlyNoId",
url: "{controller}/{action}/{seofriendly}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, seofriendly = "" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}