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

Edited Unassigned: Dealing with Route Collisions in Att. Based Routing [1403]

$
0
0
Hi,

For the sake of definition, I'm defining "collision" as 'distinct controllers registering the same route via the new attribute based routing feature'.

In my company we've opted to use a header to deal with version selection instead of adding it to the route. This will lead to multiple route collisions when my Web Api web application hosts multiple versions of the API.

I've built and attached a small application to test how Web API V2 deals with the scenario of route collisions.

I've provided my own implementation of __IHttpControllerSelector__ to allow myself to select the correct controller,

When I browse to ~/api/values I receive the following error screen.
![Image](http://i.imgur.com/QVEZhRX.png)

I rebuilt and have stepped through the 5.0 WebStack code and noticed that after selecting the relevant controller, the framework then goes to the __ApiControllerActionSelector__ and calls __FindMatchingAtions__.

Stepping through I see that we then call __GetInitialCandidateWithParameterListForDirectRoutes__ passing in the 2 subroutes (in the ~/api/values case).

__Now this is where my question arises.__

__GetInitialCandidateWithParameterListForDirectRoutes__ is passed a __HttpControllerContext__ and an enumerable of __IHttpRouteData__. The issue is that some of these subroutes are not necessarily actionable within this controller context.

In the sample project, subroutes is a collection of two, one from the ValuesController and the other from the NewValuesController. Coming into this method one of these controllers is guaranteed to be specified however this method does not scope the candidates to this controller. This is causing a dictionary KeyNotFound exception to be thrown further on down in the __FindActionMatchRequiredRouteAndQueryParameters__ function.

I've modified the __GetInitialCandidateWithParameterListForDirectRoutes__ method to continue if the route can't be traced back to the passed in ControllerContext.ControllerDescriptor and my scenario work, though breaks ~25 unit tests.

__Is this intentional?__
__Am I going about this wrong?__
__Is there a better way to handle Route Collisions as I've defined them?__ I understand that there is an Order and a way to specify precedence, but I'm unsure I i could use this mechanism in my scenario.

Thank you immensely, I absolutely love the framework.
~Derek Chasse

Viewing all articles
Browse latest Browse all 7215

Trending Articles



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