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 ?
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?
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 :)
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.
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 ?
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!!
Hi everyone!
Same scenario here, did you found any solution?
Thanks
S
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
Hi Nik, thanks for your answer.
Actually
PlunginController
attribute is an half-solution for me, what I'd like to achieve is something likeDo you succesfully used a
RoutePrefix
attribute on aUmbracoApiController
? Using a routeprfix like this[RoutePrefix("api/v2/Members")]
with an UmbracoApiController the uri should bebut 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
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:
Component:
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 theRoute
attributes on the Actions themselves. But I don't see why this shouldn't work.THanks
Nik
Hi
Have the same issue in a complete clean and new Umbraco 12.0.1 ? Did any find a solution ?
is working on a reply...