Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes a partial match break the WebApi HTTP route scanning?
    primarykey
    data
    text
    <p>I was under the impression that in MVC4 the WebApi would attempt to match the first rule, and if it was not successful then it would go on to the next rule. But in my application for some reason there is a partial match on the first rule that causes MVC4 not to attempt the second rule. Here is the example:</p> <pre><code> public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute( name: "ApiByAction", routeTemplate: "api/{controller}/{action}", defaults: new { action = "Get" } ); } public class MyController: ApiController { public Boolean GetMyAction(string Param1, string Param2) { return true; } } </code></pre> <p>The rules above are the default rules, and I've got a GET call with this url <code>/api/MyController/MyAction?Param1=xxx&amp;Param2=yyy</code>. This is matching the first rule since id is optional, and the parameter plus request method (GET) are also the same as the controller action. But if I flip the two rules around, I don't get a match anymore. </p> <p>I get an error <code>No action was found on the controller MyController that matches the name "MyAction"</code>. In the controller my action name is <code>GetMyAction</code>, so it makes sense that it won't match. But why won't it go to the next rule, which I know will match?</p> <p>On the flip side of this problem I do have other controllers with multiple GET actions and no parameters. So in order to not get a multiple match error on the <code>DefaultApi</code> rule I need to match by name first.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload