나는이 웹 API 프로젝트에 정의 된 다음 컨트롤러 : 위의 경로는 모두 기본적으로 내가 원하는 마지막 하나를 제외하고 작동ASP 닷넷 속성 라우팅, POST 및 하위 자원에 작동하지 않는 PUT
[RoutePrefix("api/installations")]
public class InstallationsController : BaseController
{
// GET all
[Authorize]
[Route("")]
public async Task<IHttpActionResult> Get(){ /*...*/}
// GET single
[Authorize]
[Route("{id:int}")]
public async Task<IHttpActionResult> GetInstallation(int id){ /*...*/}
//POST new
[Authorize]
[Route("")]
public async Task<IHttpActionResult> PostInstallation(ViewModels.Installation installation){ /*...*/}
//PUT update
[Authorize]
[Route("{id:int}")]
public async Task<IHttpActionResult> PutInstallation(int id, ViewModels.Installation installation){ /*...*/}
// DELETE
[Authorize]
[Route("{id:int}")]
public async Task<IHttpActionResult> DeleteInstallation(int id){ /*...*/}
[Authorize]
[Route("{id:int}/newimage")]
[HttpPut]
public async Task<IHttpActionResult> PutNewImageUri(int installationId){ /*...*/}
}
(api/installations/1/newimage)에 PUT을 해보고 Blob Storage에 바이너리 데이터를 업로드하는 링크를 얻으십시오. 내 문제는 어떤 POST 또는 PUT (및 아마도 삭제) "후" "{id : int}"필드에 작동하지 않습니다 것 같습니다. 내가 다른 컨트롤러에서이 문제를 가지고 실제로 잘 작동 GET :
[RoutePrefix("api/customers")]
public class CustomersController : BaseController
// GET related items
[Authorize]
[Route("{id:int}/{subitem}")]
public async Task<IHttpActionResult> GetCustomerChild(int id, string subItem)
이는 "API/고객/1/anystring"에 GET 요청을 호출됩니다, 그리고 내가 단지 "/ 설치"했을 때 일 "/ {subitem}"대신 변수로 사용됩니다. 내 PUT 처리기를 "{id : int}/{imageAction}"으로 변경하면 작동하지 않습니다. 내 WebApiConfig 클래스에서
난 단지 다음 (어떤 규칙 기반 라우팅)이 없다 : 나는 여러 비슷한 질문을 찾았하는 나는 단지이 응답을 얻을 브라우저에서
config.MapHttpAttributeRoutes();
,하지만 솔루션을 get a list of attribute route templates asp.net webapi 2.2
그것은 내 RO과 같습니다 :이 질문의 코드를 사용하여 디버깅하려고 시작했습니다
{
"message": "No HTTP resource was found that matches the request URI 'https://localhost:44370/api/installations/6/newimage'.",
"messageDetail": "No action was found on the controller 'Installations' that matches the request."
}
: 그건 내 문제가 해결 ute/function은 RouteEntries 목록에 int를 표시하지만 내 요청과 일치하지 않는 것 같아서 이것을 더 디버깅 할 수있는 좋은 제안을 찾을 수 없습니다. 모든 포인터는 감사하겠습니다!
그것을인가를 그들은 돈 때문에 일치하지 않니? –
오 하나님, 물론입니다 .. 그리고 나는 이전에 다른 컨트롤러에서 이와 똑같은 문제를 겪었습니다. 그 당시에도 똑같은 실수를했을 것입니다. 이것은 StackOverflow에 대한 나의 첫 번째 질문입니다. 어떻게 든 내 의견을 답으로 표시 할 수 있습니까? 아니면 제목을 실제 문제와 관련이 없으므로 삭제해야합니까? – Martin
사용자가이 문제를 다시 접할 경우를 대비해 제안 사항이있는 답변을 추가했습니다. –