【发布时间】:2016-04-21 15:47:54
【问题描述】:
我正在向其他 Web API 控制器添加方法。测试我能够达到我的断点的现有方法之一。但是,如果我尝试调用其中一个新的,我会得到 404。我正在使用 IIS Express 和 Postman 进行本地测试。下面的例子,你知道是什么原因造成的吗?
当我尝试调用新端点时,这是我收到的响应:
{"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.
}
端点: http://localhost:53453/api/test/addnewconnection
【问题讨论】:
-
您在 addnewconnection 周围缺少“”
-
在实际代码中添加了引号。我在将问题添加到 StackOverflow 时创建了一个类型。
-
在声明路由时,我通常使用完全限定的路由 [ActionName("ReIndex")] [Route("api/autocomplete/reindex")]
-
可以肯定的是,您是否完全回收了 IIS Express? (有时它会让应用程序的旧实例在内存中运行......)
-
那个我没做过,让我试试。我认为在使用 IIS express 时没有必要这样做。
标签: c# .net asp.net-web-api asp.net-web-api2