난 그냥 asp.net의 MVC 4 응용 프로그램과 내가 오류 브라우저에서 http://localhost:51416/api/get
를 입력하지만 얻어서 방법 GET()를 호출하려고했던 그런WebApi 컨트롤러 메서드를 호출하는 방법?
public class UserApiController : ApiController
{
// GET api/default1
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/default1/5
public string Get(int id)
{
return "value";
}
// POST api/default1
public void Post(string value)
{
}
// PUT api/default1/5
public void Put(int id, string value)
{
}
// DELETE api/default1/5
public void Delete(int id)
{
}
}
추가 기본 webapi 컨트롤러 만들었습니다
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost:51416/api/get'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'get'.
</MessageDetail>
</Error>
을
내 경로 설정 :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
//defaults: new { controller = "UserApiController", id = RouteParameter.Optional }
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
가 왜 기본적으로 작동하지 않습니다? 문제를 해결하려면 어떻게해야합니까?
'http : // localhost : 51416/api'가 생성되었습니다. 리소스를 찾을 수 없습니다. 'http : // localhost : 51416/api/userapi'가 작동합니다. 'http : // localhost : 51416/api' 경로를 고치는 방법? – Kuncevic
default : new {controller = "UserApiController", id = RouteParameter.Optional}'기본값을 지정하기 때문에'http : // localhost : 51416/컨트롤러 – nemesv
에 대한 컨트롤러가'defaults : new {controller = "UserApiController", id = RouteParameter.Optional}'와 연결되어 있었지만 여전히 리소스를 찾을 수 없습니다. 'localhost : 51416/api /' – Kuncevic