Replies: 1 comment 9 replies
-
Hmmm... do you happen to have the world's simplest repro? I'm not able to recreate the conditions. Which version of the library are you using? This might be related to something that has already been fixed. My initial guess is that this is related to mixing convention-based routing with direct routing (aka attribute routing). Due to limitations in the Web API routing system, this is strongly discouraged. There are edge cases where things will not work as expected. This could be one of the them. I also noticed that you included the It's not possible to have an unversioned route. All actions will have an implicit and explicit corresponding API version. The only exception is version-neutral, which accepts all versions, which should be used with caution. Another callout is that I see the API Explorer being added from The issue is definitely not related to configurating versions by convention. The API Explorer extensions use the API version associated with the action. When For your convenience, I've modified the provided example with your configuration to demonstrate things working. Perhaps that can help you work backward and determine where your application is different. Some additional notes:
|
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm working on a Web API 2 (.NET Framework 4.7.1, not .NET Core) with Swagger, including API versioning. I'm using the URL path versioning approach - as long as I attach the supported ApiVersion-Attributes to the controller, it works fine.
The WebAPI startup looks like this:
But I have more than one single controller in the WebAPI, so everytime I add/specify a new version, I have to attach the new ApiVersion attribute to all of the controllers. Because of this effort, I tried to integrate "controller conventions" to be able to configure the ApiVersion-attributes per controller more centrally. So I changed the upper WebAPI configuration like this:
Then, so I thought, I could remove the ApiVersion attributes from the controller, like
But I got the following error, if I try to load the Swagger UI:
The method 'get' on path '/api/v/Item/GetData/{userId}/{password}/{key}' is registered multiple times (check the DefaultUrlTemplate setting [default for Web API: 'api/{controller}/{id}'; for MVC projects: '{controller}/{action}/{id?}']).
Obviously, the controllers RoutePrefix defition
[RoutePrefix("api/v{version:apiVersion}/Item")]
won't be substituted anymore.Has anybody a clue, what causes this problem?
Thanks in advance.
Best regards,
Tom
Beta Was this translation helpful? Give feedback.
All reactions