Open andrew-laughlin opened 6 years ago
@andrew-laughlin I am afraid that the Web API OData routing doesn't support your scenario now, because just you found, it's using the controller name to match.
For the attribute routing, you can add as follows, but at the end, it's return to compare the controller name.
[ODataRoute("Sensors", RouteName = "ODataRouteV1")]
public IActionResult Get()
[ODataRoute("Sensors", RouteName = "ODataRouteV2")]
public IActionResult Get()
I mark it as feature
and it's better to find a solution in the next release.
@xuzhg thanks very much for the info. I'll look for an alternate solution. Should this be closed?
@andrew-laughlin I'd love to keep it open because I think it's a nice to have feature in the next version.
In case anyone is interested, to work around this issue in the interim, we've implement a custom routing solution based on info here --> http://odata.github.io/WebApi/#03-04-custom-routing-convention
Essentially the code implements IODataRoutingConvention
and inserts itself as the first routing convention. It then processes all existing conventions and, if necessary disambiguates the results (read: list of actions) returned by any existing routing convention handler. Our disambiguation is based on version, but any criteria could be used.
Is there a plan to implement this? currently i have my api separated in areas of concern, i was able to separate almost everything but the same happens to me, the router selects any of the controllers disregarding namespace and pretty much everything.
@andrew-laughlin your link is not working anymore. Where can i find the documenation about the workaround now ? Thanks
@icnocop thanks a lot !
I have 2 controllers with the same name, but in different namespaces. Both have GET actions with differing parameter lists. I'm using convention-based routing.
This is successful: http://localhost:3000/v2/odata/tenants/myTidGuid/Sensors
This results in the exception below: http://localhost:3000/odata/Sensors
As shown above, the v2 controller is selected for the v1 route. In the code below (from ODataActionSelector.cs)
considerCandidates
contains GET actions from both v1 and v2 controllers. However it's not able to disambiguate and just returns FirstOrDefault(), which happens to always be the v2 controller. So the v2 route works, but v1 doesn't.Assemblies affected
Microsoft.AspNetCore.OData 7.0.0.B4
Reproduce steps
The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.
Expected result
The correct controller should be selected based on the registered route.
Actual result
The correct controller is not selected.
Additional detail
I've tried various forms of attribute routing without success. It does work with MVC routing, however the entities are not returned in an OData JSON envelope, which will break clients.
Any idea what I'm doing wrong?