-
Notifications
You must be signed in to change notification settings - Fork 704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug when the same Controller name #630
Comments
I've heard about people trying to version their UIs, but I've never seen it. It seems strange to me, but I'm sure you have your reasons. API versioning doesn't care about controller names. In fact, it doesn't really care all that much about controllers. Grouping and matching is done at the action level as defined by it's route template. The thing that is versioned is the resource behind a path, not the controller (though it may seem that way to the implementer). The failing request is for |
Thank you, but according to
According to the described logic, when the version property of my But because I added Maybe it's the problem I described, I should change it. This problem will occur when the name of the Controller under my area is the same as the name of the Controller in the root directory, and apiversion is not passed, but only according to |
The controllers you mentioned have 2 different routes:
Regardless of the API version value, API versioning sees these as different routes and APIs. In a RESTful application, the URL (path) is the resource identifier; therefore, the resources and API versions are expected to be potentially different. The CurrentImplementationApiVersionSelector selects the current (e.g. maximum) API version for a given route/API. From the configuration I can see, I expect the following: Request 1 GET home/getjson HTTP/1.1
Host: localhost HTTP/1.1 200 OK
api-supported-versions: 1.0, 2.0
content-type: application/json
content-length: 35
"Test.ApiVersioning.Controllers.v2" Request 2 GET user/home/getjson HTTP/1.1
Host: localhost HTTP/1.1 200 OK
api-supported-versions: 1.0
content-type: application/json
content-length: 46
"Test.ApiVersioning.Areas.User.Controllers.v2" API Versioning doesn't care about folder names or how you organize your code. It only cares about routes, which map to actions, and may take some shared data from controllers. The mapping is pre-computed at startup. |
In fact, the folder "Test.ApiVersioning.Areas.User.Controllers.v2" is an empty folder. I only added the v1 folder and the corresponding Controller. "API Versioning doesn't care about folder names or how you organize your code. It only cares about routes, which map to actions, and may take some shared data from controllers. The mapping is pre-computed at startup." According to the understanding of this sentence, I can think that Request 2
But in the actual test, I get the following result Request 1
Request 2
Request 3
Using I added the |
Hello, I added support for Area in In
The At the same time I added the |
Ah ... good find. Been quite some time since I looked at this. Now, I remember why this is. Given the set of action descriptors and their routes, the only thing to really key off of is the controller name, which can be extracted from the route parameter or fall back to the descriptor's controller name. You certainly have a unique setup. I haven't seen any versioning attempts with a UI in a while and never using areas too. I'm not yet convinced this is a behavior that should be intrinsically baked in. I find two different logical resources that have the same name to be strange. I see how it can happen for "Home", but not for others. OData users run into similar problems trying to use different route prefixes. I've seen somewhat similar setups solved by using nested applications. Grouping by route template would be more accurate, but it comes with its own problems. For example, The best solution for you is to extend and change the ApiVersionCollator as you've done. You can then replace the default implementation in the service collection which is registered here any time after If a compelling argument can be made that this scenario is somehow common, I'd entertain the idea of an enhancement. I need to be conservative in adding such things because it can easily turn into a slippery slope of special cases. I also have to consider down-level support in Web API, which is still heavily used. For the moment, things are behaving exactly as expected. If you need assistance adjusting your setup to replace the default collator, feel free to ask. It seems like you're on the path to a working solution. Thanks |
Yes, this question is not a universal one, but the main point is whether to distinguish between area and non-area controllers. I will consider expanding or changing ApiVersionCollator after AddApiVersioning (), so that the code changes are minimal thank you very much! |
No problem. Good discussion. This may be useful to someone else. ;) |
There is a project :Test.ApiVersioning.
When I request the following URLs separately, the following result appears:
When the same Controller Name exists, version control seems to add version information that should not be added to other same Controllers, resulting in the inability to normally access the logically accessible Controller.
Startup.ConfigureServices:
emmmm....
It seems that Api.Versioning controls the available versions only based on the name of the Controller. When I add a v3 HomeComtroller in the User directory, the https://localhost:44311/home/getjson is not accessible. The api-supported-versions are 1.0, 2.0, 3.0
The text was updated successfully, but these errors were encountered: