이미 여러 컨트롤러가있는 MVC 4 응용 프로그램에 새 컨트롤러 "LoggingController"를 추가했습니다. 이제이 컨트롤러의 라우팅 동작이 이미 존재하는 것과 다른 것으로 나타났습니다.ASP.NET MVC 4 : 하나의 컨트롤러 라우팅이 다른 컨트롤러와 다릅니다.
예를 들어 다음 두 URL은 예상대로 제대로 작동하고 BlogController의 "Index"메서드를 누르십시오.
http://localhost:56933/Blog/
http://localhost:56933/Blog/Index
그래서 추가를 제외한 다른 모든 컨트롤러 수행
http://localhost:56933/Logging/Index
을 - 제대로 작동
http://localhost:56933/Logging/
LoggingController에서 "인덱스"방법 명중 - '/'응용 프로그램에 서버 오류 반환 " . 자료를 찾을 수 없다."
뚜렷한 것 이외에 어디서부터 살펴보기 시작해야합니까?
다음은지도 노선의 특정 컨트롤러에 특정 아무것도 없다 LoggingController
public ActionResult Index(int? page, string Period, string LoggerProviderName, string LogLevel, int? PageSize)
에서 색인 서명입니다. 참조 용 전체 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 }
);
}
나는 본다! 기본 값을 선택했습니다. 이상하게도 Index 메서드를 수정했을 때 충분하지 않았습니다. 컨트롤러 + 인덱스를 삭제하고 다시 만들 때 예상대로 작동하기 시작했습니다. 어쨌든 이제는 모두 좋다. – Evgeny