我已经阅读了这些问题:
Multiple actions were found that match the request: webapi
Web API Routing - multiple actions were found that match the request Multiple actions were found that match the request Web API?
我已按照以下方式更新了我的RouteConfig:
routes.MapRoute(
name: "Receipt",
url: "api/{controller}/{action}/{id}",
defaults: new { controller = "Receipt", action = "Post", source = UrlParameter.Optional }
);
创建这个新的路线图并没有帮助解决问题
这里是Controller中的相关功能:
public HttpResponseMessage Post ([FromBody]CreateReceiptViewModel source)
{
try
{
// stuff happens here
}
catch (Exception ex)
{
// something went wrong, save exception data to the database
// RecordError(ex, "Post Receipt", "ReceiptController/Post");
}
}
//public void RecordError(Exception ex, string action = "", string origin = "PocketPlooto API")
//{
// Error Error = new Error
// {
// Date = DateTime.Now,
// Detail = ex.ToString(),
// Message = ex.Message,
// Origin = origin,
// StackTrace = ex.StackTrace,
// Action = action
// };
// db.Errors.Add(Error);
// db.SaveChanges();
//}
功能相当大,所以我觉得包含在这里是不切实际的。
有趣的是,在评论RecordError
时,帖子很好。
如果我取消注释,则会发生错误(我的测试环境不允许我以JSON以外的格式查看它,对此造成的不便表示歉意):
"消息":"发生了错误。",
" ExceptionMessage":"找到了与请求匹配的多个操作:\ r \ n类型为WebApiService.Controllers.ReceiptController \ r \ n \ nRecordError类型WebApiService.Controllers.ReceiptController",
" ExceptionType":" System.InvalidOperationException&#34 ;,
"堆栈跟踪":" System.Web.Http.ApiController上的System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\ r \ n在System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\ r \ n中.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)\ r \ n在System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"
不幸的是,我不太了解堆栈跟踪,因为这里没有任何重复的操作,我甚至无法猜测Web Api正在做什么或为什么会出现此问题控制器是个问题。
任何人都可以清楚地了解堆栈跟踪的含义以及额外功能出现问题的原因吗?
答案 0 :(得分:2)
如果不需要从外部访问私有方法 设置该方法的[NonAction]属性。