Issue with multiple routes on a controller method #896
Unanswered
orryverducci
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Are you using the API Explorer extensions? It will be required. By setting, Without seeing more of the setup, I don't have any other immediate ideas. This looks like it should work. If you have the world's simplest repo, that will go a long way in helping troubleshoot the problem. As an aside, you might consider returning 501 (Not Implemented) unless an empty array is truly a valid response. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've hit an issue with ASP.NET API Versioning and a controller which has multiple routes to a single method.
Basically I'm working on an application which needs to implement an external API specification. That specification has multiple API versions which can be implemented, indicated to the application in the URL path, so I'm using ASP.NET API Versioning to achieve this.
In one controller I have multiple URL paths, which the specification requires me to implement, but in my application I don't have anything to return on those paths. So I've put multiple routes, via HttpGet attributes, on to a single method which returns the same response (an empty array) to all those routes.
However when I do so the API version part of the URL path only works as expected on the first route defined on that method. The additional routes will return a response on any API version, not just the version the controller specify it supports. In addition for those routes Swagger shows the API part of path as being "v{version}" instead of the expected API version, as you'll see below:
Here's the code for the controller
It's easily worked around by giving each route their own method, but as they're identical it doesn't feel like it's the cleanest solution. Not sure if I'm missing something here, or if I've hit a limitation of the library, so any guidance would be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions