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

Edited Issue: Incorrect action is being matched as explicit route order is not being honored [1242]

$
0
0
__Scenario__:
User has a CountriesController. He would like retrieve a country information based on id or name.


__Setup of Controller__:
Here since logically the route templates are the same for an incoming request, a user might want to explicitly order them so that the appropriate action gets chosen.
```
[RoutePrefix("api/countries")]
public class CountriesController : ApiController
{
[Route("{id:int}", Order = 1)]
public string GetById(int id)
{
return "GetById:" + id;
}

[Route("{name}", Order = 2)]
public string GetByName(string name)
{
return "GetByName:" + name;
}
}
```

__Issue__:
Request for "api/customers/10" is hitting the action "GetByName" as opposed to "GetById".
Also I noticed that if I do not have explicit ordering, then things are working fine. But a user might not want to rely on this and would probably want to explicitly set the order. In this case we need to honor it.

```
Method: GET, RequestUri: 'http://kirandesktop:9095/api/customers/10', Version: 1.1, Content: <null>, Headers:
{
}
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Date: Thu, 22 Aug 2013 17:55:18 GMT
Server: Microsoft-HTTPAPI/2.0
Content-Length: 14
Content-Type: application/json; charset=utf-8
}
"GetByName:10"
```

__Attached__ a standalone katana selfhost repro.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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