ASP.NET MVC 4 프로젝트를 HomeController로 만들지 않고 기본 컨트롤러를 어떻게 설정 합니까?
응용 프로그램이 시작될 때 기본 영역을 어떻게 설정해야 합니까?
답변
가장 좋은 방법은 경로를 변경하는 것입니다. 기본 경로 (App_Start에 정의 됨) 세트/Home/Index
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters*
new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
기본 방문 페이지로 원하는 경로로 변경할 수 있습니다.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters*
new { controller = "Sales", action = "ProjectionReport",
id = UrlParameter.Optional }
);
답변
App_Start 폴더의 RouteConfig.cs 에서 아래 코드 설정
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional });
}
여전히 작동하지 않으면 아래 단계를 수행하십시오.
두 번째 방법 :
아래 단계를 따르십시오.
1) 프로젝트를 마우스 오른쪽 버튼으로 클릭하십시오.
2) 속성 선택
3) 웹 옵션을 선택하고 특정 페이지 (컨트롤러 /보기)를 선택한 다음 로그인 페이지를 설정합니다.
여기서 계정은 내 컨트롤러이고 로그인은 내 작업 방법입니다 (계정 컨트롤러에 저장 됨).
첨부 된 스크린 샷을 보세요 .
답변
이 질문에 대한 답변을 보지 못했습니다.
응용 프로그램이 시작될 때 기본 영역을 어떻게 설정해야 합니까?
따라서 기본 영역을 설정하는 방법은 다음과 같습니다.
var route = routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
).DataTokens = new RouteValueDictionary(new { area = "MyArea" });
답변
컨트롤러가 하나만 있고 루트의 모든 작업에 액세스하려면 다음과 같이 컨트롤러 이름을 건너 뛸 수 있습니다.
routes.MapRoute(
"Default",
"{action}/{id}",
new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
답변
