Last post Feb 08, 2019 06:56 AM by AddWeb Solution
Jun 27, 2018 08:00 PM|Mike Wodarczyk|LINK
I spent several hours working on a new web api controller that was giving "not found" responses from the web client.
Eventually I found that in another area of the web site, in a different name space with a different RoutePrefix I used the same controller name for a totally different context. By area, I mean that there were separate AreaRegistration implementations, folders,
namespaces, routes, etc. for different modules of the asp.net web site. My Shipping area had a SkuAliasApiContoller which was referring to allowed substitutions and the sales order area had a SkuAliasApiController that referred to customer's aliases for SKUs.
With these 2 identically named controllers, they both stopped each other from working.
Granted that it is a bad idea to use the same name for 2 controllers, but working on a team, I may never know about the other area's code.
There were no warnings from Visual Studio 2017, no errors from the asp.net routing engine. It just dropped both controllers from the routing.
Seems like this is a bug in the routing.
Jun 27, 2018 09:34 PM|PatriceSc|LINK
Done a quick check and it seems I see the same behavior. And you do have a message when not using prefixes. Hopefully someone at MS will pick that here or try maybe to file an issue at https://github.com/aspnet/AspNetWebStack ?
Jun 28, 2018 08:18 AM|Yohann Lu|LINK
Hi Mike Wodar,
You can try to use the [RoutePrefix]
attribute to avoid this error.
Attribute Routing in ASP.NET Web API 2:
Feb 07, 2019 10:33 AM|Torsten-R|LINK
We use Route("prefix") attributes at controller classes, that does not help against duplicate controller class names.
Feb 08, 2019 06:56 AM|AddWeb Solution|LINK
If You Got 404 error while calling API Than, you have to add follow code at top of the api
[httpGet](as yo have)
* same route name call on your mvc controller with proper syntex, its surely works fine for you.