웹 API 2를 사용하고 ASP.Net 4에서 개발 중입니다.이 샘플 코드는 webapi를 배우려고합니다. 두 가지 경로가 있습니다. 첫 번째 경로는 주어진 상점의 서비스 자원입니다. 두 번째 경로는 저장소 리소스 경로입니다.왜 웹 API가 내 리소스를 찾지 못합니까?
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Services",
url: "store/{id}/services",
defaults: new { controller = "Services" }
);
routes.MapRoute(
name: "Store",
url: "store/{id}",
defaults: new { controller = "Store", id = UrlParameter.Optional}
);
}
두 번째 경로 "저장소"는 완벽하게 작동합니다. 첫 번째 경로는 상점에서 사용할 수있는 모든 서비스를 자세하게 설명하는 것입니다. 내가
을하려고 할 때 404 오류가 발생합니다. 누군가 내가 뭘 잘못하고 있는지 가리킬 수 있습니까?/API/저장/1/서비스
다음은 컨트롤러
namespace APITestter1.Controllers
{
public class ServicesController : ApiController
{
public string Get(int id, string prop = "xxx")
{
return "Hello services World!" + id + " added attribute " + prop;
}
public string Post(int id, string prop = "xxx")
{
return "Hello Post World!" + id + " added attribute " + prop;
}
}
}