1

Closed

'{action}' variable on controller-route not considered during action matching

description

For the following controller, a request like "/api/customers/GetAllCustomers1" is resulting in "Multiple actions found..." error

Attached a standalone katana repro.
    [Route("api/customers/{action}")]
    public class CustomersController : ApiController
    {
        public string GetAllCustomers1()
        {
            return "GetAllCustomers1";
        }

        public string GetAllCustomers2()
        {
            return "GetAllCustomers2";
        }
    }
Reason:
We need to following similar approach like convention routing does for '{action}' variable. Interesting piece of code:

ApiControllerActionSelector source:
                if (routeData.Values.TryGetValue(RouteKeys.ActionKey, out actionName))
                {
                    // We have an explicit {action} value, do traditional binding. Just lookup by actionName
                    ReflectedHttpActionDescriptor[] actionsFoundByName = _standardActionNameMapping[actionName].ToArray();

                    // Throws HttpResponseException with NotFound status because no action matches the Name
                    if (actionsFoundByName.Length == 0)
                    {
                        throw new HttpResponseException(controllerContext.Request.CreateErrorResponse(
                            HttpStatusCode.NotFound,
                            Error.Format(SRResources.ResourceNotFound, controllerContext.Request.RequestUri),
                            Error.Format(SRResources.ApiControllerActionSelector_ActionNameNotFound, _controllerDescriptor.ControllerName, actionName)));
                    }

file attachments

Closed Aug 29, 2013 at 6:06 PM by kichalla
Verified.