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

Commented Issue: Default ordering should place most specific routes before routes with variables [1246]

$
0
0
When I make a request like “/api/countries/dosomething”, I am receiving the following error:

{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id'
of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in 'SampleOwinApp.CountriesController'. An op
tional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}

Controller:
```
[RoutePrefix("api/countries")]
public class CountriesController : ApiController
{
[Route("{id}")]
public string Get(int id)
{
return "country info";
}

[HttpGet]
[Route("dosomething")]
public string DoSomething()
{
return "DoSomething";
}
}

```

__Expected__: When user does not specify an order explicitly, we should have a default ordering where the most specific routes come before any routes having variables.
Comments: This is related to 1238, but different. Part of the tension here is that: - Get(id) matches more parameters; but - DoSomething() has a higher precedence. So there's a design ambiguity about which wins. In the current implementation, we first take the matches that have the most parameters, and then filter on precedence. But flipping that order wouldn't necessary be correct either. We could probably come up with some more interesting test cases where this breaks.

Viewing all articles
Browse latest Browse all 7215

Trending Articles