2016-07-07 2 views
1

MVC4 영역, 홈 컨트롤러 및 라우팅

이 조언을 따르고 지금 실행 중입니다. 그러나/area/home/index를 치면 올바른 컨트롤러 동작이 실행되지만 Area 폴더의 Index.cshtml이 아닌 루트 사이트의 Index.cshtml을 사용하고 있습니다! 어떤 아이디어를 "수정"하는 방법?

동일한 작업을 수행하기 위해 라우팅을 처리하는 더 좋은 방법이 있습니까?

목표 : http://example.net/ -> HomeController/인덱스 (루트)
http://example.net/area1 -> area1.HomeController.Index/영역 1의 Index.cshtml
http://example.net/area1/NotIndex -> area1.HomeController.NotIndex/영역 1의 NotIndex.cshtml
http://example.net/area2 - > area2.HomeController.Index/area2 's Index.cshtml
등 ...

다른 영역의 속성 라우팅을 시도했습니다.

[RouteArea("ProductReuse")] 
[Route("ProductReuse")] 
public partial class ProductReuseController : BaseProductReuseController 
{ 
    [HttpGet] 
    [Route("Index")] 
    public ActionResult Index() 
    { 
     if (SessionUserLogin == null) return LoginActionResult(SessionAppName); 

     var serviceResponse = _productReuseService.IndexQuery(SessionUserId); 
     var response = _mapper.Map<IndexViewModel>(serviceResponse); 

     return View(response); 
    } 
    ... 
} 

이 가까이 있지만 여전히처럼 보이는 URL이 있어야 : 당신이 밖으로 http://example.net/ProductReuse 그것을 폭탄을 공격하려고하면 http://example.net/ProductReuse/Index

합니다.

TIA

답변

0

라우팅 속성에 빈 문자열 경로 이름을 추가 할 수 있음을 발견했습니다.

[RouteArea("ProductReuse")] 
[Route("ProductReuse")] 
public partial class ProductReuseController : BaseProductReuseController 
{ 
    [HttpGet] 
    [Route("Index")] 
    [Route("")] // Use an empty name to set the default page... 
    public ActionResult Index() 
    { 
     if (SessionUserLogin == null) return LoginActionResult(SessionAppName); 

     var serviceResponse = _productReuseService.IndexQuery(SessionUserId); 
     var response = _mapper.Map<IndexViewModel>(serviceResponse); 

     return View(response); 
    } 
    ... 
}