2

Closed

Web API - In some cases query parameters break the routes

description

If you have API route that is defined as:
        routes.MapHttpRoute(
            name: "DefaultApi2",
            routeTemplate: "api/event/{eventName}/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
The route itself works until you tried to use query parameters. The example application is enclosed.

file attachments

Closed Jul 19, 2012 at 12:36 AM by hongyes
Verified

comments

HongmeiG wrote Apr 13, 2012 at 8:41 PM

Could you please tell us the url that will break this route? What is the sympton?

pvasek wrote Apr 15, 2012 at 6:59 PM

It is included in attached app. Complete description and examples of working and not working urls.

these work:
api/event/testevent1/values
api/event/testevent1/values/1

these don't:
api/event/testevent1/values?param1=value1
api/event/testevent1/values/1?param1=value1

pvasek wrote Apr 16, 2012 at 7:26 AM

Symptom: for not working urls you get:
"No action was found on the controller 'values' that matches the request"

pvasek wrote Apr 18, 2012 at 9:24 AM

LittleClive point me out (http://forums.asp.net/p/1791915/4938255.aspx/1?p=True&t=634703231251623945) that I can add eventName as parameter for the action.
But this in this case I can not move the code for switching between different dbs out from my actions and this behavior is different from that we have in MVC.

BradWilson wrote Apr 19, 2012 at 5:14 PM

Thanks for the bug report. We're looking into this.

yaohuang wrote Apr 24, 2012 at 8:45 PM