Copied to clipboard

Flag this post as spam?

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


  • tteglas-usrc 1 post 21 karma points
    Feb 03, 2021 @ 14:34
    tteglas-usrc
    0

    Microsoft.AspNet.WebApi.Versioning doesn't work with UmbracoApiController.

    Hey everyone,

    I have integrated the NuGet package Microsoft.AspNet.WebApi.Versioning in order to try and version my API controllers (which are inheriting UmbracoApiController). Now the problem I'm having is that Umbraco 8.6.6 throws "Umbraco.Core.Exceptions.BootFailedException: Boot failed." stating that: "A route named 'umbraco-api-{my controller's name here}' is already in the route collection. Route names must be unique."

    I have to state that even though I'm having the same controller name, the namespace is completely different, it does not exist in the same namespace (that would cause a compile time error too).

    What I could find is that after throwing that exception, the RouteTable.Routes object contains the Route definition of each and every controller I have created in my project. The Route should be a definition to where a request should be mapped towards, so it shouldn't contain the exact path to each controller.

    I have exhausted every option I could think of and find on the web on this matter, so please do not point me to some Umbraco official documentation as I've gone through that more than several times without luck in trying to figure this one out.

    Has anyone integrated this NuGet package and have UmbracoApiControllers versioned ?

  • ianhoughton 281 posts 605 karma points c-trib
    Feb 24, 2021 @ 19:26
    ianhoughton
    0

    I'm also experiencing the same trying to incorporate an existing versioned API into an Umbraco solution.

    Haven't found a fix either, but at least your not the only one!!

  • Stefano Beretta 101 posts 246 karma points
    Mar 25, 2021 @ 12:24
    Stefano Beretta
    0

    Hi everyone!

    Same scenario here, did you found any solution?

    Thanks

    S

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Mar 25, 2021 @ 12:37
    Nik
    1

    I don't know if this will actually help or not, but have you tried adding the PluginController attribute to your controllers, ensuring they have unique "areas".

    From an MVC/Web API perspective, the PluginController allows you to define the Area for the route. However, I'm not sure if that is used when Umbraco is registering the route.

    Another alternative is to look at using Attribute Routing?

    Thanks

    Nik

  • Stefano Beretta 101 posts 246 karma points
    Mar 25, 2021 @ 13:18
    Stefano Beretta
    0

    Hi Nik, thanks for your answer.

    Actually PlunginController attribute is an half-solution for me, what I'd like to achieve is something like

    /api/vX/controller/action
    

    Do you succesfully used a RoutePrefix attribute on a UmbracoApiController? Using a routeprfix like this [RoutePrefix("api/v2/Members")] with an UmbracoApiController the uri should be

    /api/v1/Members/action
    

    but the response for me is always html of the view showed when you have no nodes created in the backoffice ("Welcome to your Umbraco installation")

    I also tried the package Microsoft.AspNet.WebApi.Versioning but it breaks every other umbraco controller :)

    Have a nice day

    S

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Mar 25, 2021 @ 13:35
    Nik
    1

    Hey Stefano.

    Yep, I'm heavily using Attribute Routing at the minute. You will need a Composer & Component to enable Attribute Routing to work. Something like this:

    Composer:

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class AttributeRoutingComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Components().Insert<AttributeRoutingComponent>();
        }
    }
    

    Component:

    public class AttributeRoutingComponent : IComponent
    {
        public AttributeRoutingComponent()
        {
            GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
        }
        public void Initialize()
        {
    
        }
    
        public void Terminate()
        {
    
        }
    }
    

    Without that, you'll find that the Attributes don't do anything.

    I've also not tried using the RoutePrefix attribute, but I generally use the Route attributes on the Actions themselves. But I don't see why this shouldn't work.

    THanks

    Nik

  • Thomas 315 posts 602 karma points c-trib
    Jul 20, 2023 @ 09:24
    Thomas
    0

    Hi

    Have the same issue in a complete clean and new Umbraco 12.0.1 ? Did any find a solution ?

Please Sign in or register to post replies

Write your reply to:

Draft