Watch out for duplicate web api controller names in large projects causing url not found problems RRS feed

  • Question

  • User-1847102984 posted

    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.

    Wednesday, June 27, 2018 8:00 PM

All replies

  • User753101303 posted


    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 ?

    Wednesday, June 27, 2018 9:34 PM
  • User36583972 posted

    Hi Mike Wodar,

    You can try to use the [RoutePrefix] attribute to avoid this error.

    Attribute Routing in ASP.NET Web API 2:

    Best Regards,

    Yong Lu

    Thursday, June 28, 2018 8:18 AM
  • User-577713914 posted

    We use Route("prefix") attributes at controller classes, that does not help against duplicate controller class names.

    Thursday, February 7, 2019 10:33 AM
  • User-1038772411 posted

    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.

    Friday, February 8, 2019 6:56 AM
  • User535721855 posted

    The issue here isn't that you have duplicate routes. The main issue is that in no way does Microsoft ASP.NET MVC tell you at any point that you have duplicate routes. You simply receive a 500 error with no description. This could easily be fixed within .NET MVC, but even now that I am using ASP.NET Core MVC, it is not fixed and I have spent many hours throughout the development of my team's project trying to figure out why we get 500 errors from time to time. It's so amateur for Microsoft's development team to have built an MVC framework (that is open source nonetheless) with so many hundreds of features but with this type of very common problem unresolved.

    Thursday, October 3, 2019 5:56 PM
  • User-474980206 posted

    it generally considered a security risk to return error information to the user, so the default is just 500. If you want more info, you need to override the default behavior.


    Thursday, October 3, 2019 7:56 PM
  • User753101303 posted


    This is what you have now for duplicate web api routes in which version? A 500 error is usually an exception which is logged by default to the Windows event log you can check for details.

    Else my next move is to check the IIS log for the sc-substatus code as in some cases, it can be some other 500.xx server side error...

    I don't remember to have ever seen a 500 code (or more generally an error) for which I really couldn't get some more information than that - though sometimes understanding the error message is another story ;-)

    Friday, October 4, 2019 9:06 AM