我正在將方法添加到其他Web API控制器。測試現有的一種方法,我可以打破我的中斷點。然而,如果我嘗試調用其中一個新的,我會得到一個404。我正在使用IIS Express和Postman進行本地測試。下面的例子,任何想法可能會導致這種情況?Web API控制器不識別新添加的方法
當我嘗試調用新端點,這是響應我收到:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:53453/api/nisperson/addnewconnection'.",
"MessageDetail":"No action was found on the controller 'NISPerson' that matches the request."}
現有方法:
[HttpPost]
[ActionName("register")]
public ClientResponse PostRegisterPerson(HttpRequestMessage req, PersonModel person)
{
// This method is getting hit if I call it from Postman
}
端點:http://localhost:53453/api/test/register
新增方法:
[HttpPost]
[ActionName("addnewconnection")]
public ClientResponse PostNewConnection(HttpRequestMessage req, string Email, String FirstName, string LastName)
{
// This is the new method which when called from Postman cannot be found.
}
端點:
[HttpPost]
[ActionName("addnewconnection")]
public ClientResponse PostNewConnection(HttpRequestMessage req, string Email, String FirstName, string LastName)
{
// This is the new method which when called from Postman cannot be found.
}
的路由處理不能映射這個URI:http://localhost:53453/api/test/addnewconnection
您在「addnewconnection」附近缺少「」「 –
在實際的代碼中添加了引號。我在向StackOverflow添加問題時做了一個類型。 –
在聲明路由時,我通常使用完全合格的路由 [ActionName(「ReIndex」)] [Route(「api/autocomplete/reindex」)] –