Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: "Multiple actions found" error due to incorrect route created by attribute routing [1144]

$
0
0

__Scenario__:
User likes to support CORS for one of his actions and so he decorates the action with HttpPost and HttpOptions attributes.

Attached a standalone katana selfhost repro.

__Controller__:
```
[RoutePrefix("api/values")]
public class ValuesController : ApiController
{
[HttpPost("")]
[HttpOptions("")]
//[AcceptVerbs("POST", "OPTIONS", RouteTemplate = "")] //NOTE: THIS WORKS
public string Echo([FromBody]string value)
{
return value;
}
}
```
__Issue__:
When I am doing a POST to this action, I am receiving the following error:

{"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were found that match the request: \r\nSystem.String Echo(System.String) on type SampleOwinApp.ValuesController\r\nSystem.String Echo(System.String) on type SampleOwinApp.ValuesController","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()"}


__Reason__:
I noticed that the above problem is due to attribute routing creating route like below for the above action. __Note__ that the 'actions' datatoken has duplicate entries for the action 'Echo'.

config.Routes.MapHttpRoute("routeName", "api/values", new { }, new { httpMethod = HttpMethodConstraints[OPTIONS, POST] }, new { actions = [Echo(String value),Echo(String value)] });

__Workaround__:
Instead of using two attributes, user could just use the following attribute:
[AcceptVerbs("POST", "OPTIONS", RouteTemplate = "")]

In this case, the route being added would something like below:
config.Routes.MapHttpRoute("routeName", "api/values", new { }, new { httpMethod = HttpMethodConstraints[POST, OPTIONS] }, new { actions = [Echo(String value)] });
Comments: It is a bug. Fixed: https://aspnetwebstack.codeplex.com/SourceControl/changeset/2aa52f95ff7fcd75f21b32e007063b29487ad03a

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>