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

Edited Issue: attribute routing doesn't always resolve overloads [1199]

$
0
0
Attribute routing doesn't work well with action overload resolution (ie, the action selector), particularly when there are multiple actions with structurally equivalent routes that have different route parameters. These routes will match the same URL, but have different route templates.

```
HttpGet(“controller/{name}”)
Action1(string name, int age)

HttpGet(“controller/{id}”)
Action2(string id, int score)
```
GET controller/xyz?score=12
Should match Action2.


Translating this into regular routing would be like this:
Although this still skirts the issue since ordering is explicitly set by the user in a central route table; whereas the attr example doesn’t set ordering. Basically, attr routing allows an ambiguity since you can have structurally equivalent routes with different route parameters names. Whereas conventional routing resolves this ambiguity by forcing you to list an explicit route order.

```
// What order are the routes in?
config.Routes.MapHttpRoute(
routeTemplate: "api/values/{name}",
defaults: new { controller="Values"}
);

config.Routes.MapHttpRoute(
routeTemplate: "api/values/{id}",
defaults: new { controller = "Values"}
);

public class ValuesController : ApiController
{
public string Get(string name, int age)
{
return "Action1: " + name + age;
}

public string Get(string id, int score)
{
return "Action2: " + id + score;
}
}
```


Viewing all articles
Browse latest Browse all 7215

Trending Articles



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