我正在玩 WebApi2 并遇到了一个奇怪的问题。
我已更新默认 ValuesController 以使用 IHttpActionResult
喜欢
public class ValuesController : ApiController
{
// GET api/values
[HttpGet]
public IHttpActionResult Get()
{
return Ok(new string[] { "value1", "value2" });
}
// GET api/values/get2
[HttpGet]
public IHttpActionResult Get2()
{
return Ok(new string[] { "value1", "value2" });
}
当我尝试在邮递员中调用 Get() 时,出现错误
{ "Message": "发生错误。", "ExceptionMessage": "找到与请求匹配的多个操作:\r\nSystem.Web.Http.IHttpActionResult Get() on type WebApplication1.Controllers.ValuesController\r\ nSystem.Web.Http.IHttpActionResult Get2() on type WebApplication1.Controllers.ValuesController", "ExceptionType": "System.InvalidOperationException", "StackTrace": " at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n 在 System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n 在 System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancelToken)\r\n 在 System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancelToken)\r\n 在 System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()" }
我是否需要为每个人手动创建一条路线才能使其正常工作?
这么简单的事情,却让我头疼!