Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jan 05, 2022 @ 13:14
    Simon Dingley
    0

    Umbraco 7 Routes Issue with Versioned Web API

    I've got a v7 site that exposes an API to support a mobile app. The API is now being versioned to continue support for legacy versions of the app. The problem I seem to be encountering is that once adding v2.0 of the API I start getting errors such as:

    A route named '######' is already in the route collection. Route names must be unique.

    This is despite me having the route prefix attribute such as [RoutePrefix("api/v2/")] on the controllers. The only way I can get rid of the error is to rename all controllers in the new version which I'd prefer not to have to do.

    In case you're wondering, I have enabled attribute routing:

    config.MapHttpAttributeRoutes();
    

    My guess is that the issue is caused by the automatic routing in Umbraco but is there any way for that to be prevented in this scenario?

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Jan 12, 2022 @ 10:32
    Marc Goodson
    1

    Hi Simon

    Shannon had a blog post about how you could do this a while back:

    https://shazwazza.com/post/need-to-remove-an-auto-routed-controller-in-umbraco/

    I guess it depends on how many you have and whether it's ok to just hardcode their removal, or whether you need to do something cleverer...

    Hope it helps anyway.

    regards

    marc

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jan 17, 2022 @ 12:02
    Simon Dingley
    0

    Thanks Marc, this gives me something to go on.

Please Sign in or register to post replies

Write your reply to:

Draft