Copied to clipboard

Flag this post as spam?

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


  • Jannich Ibsen 10 posts 90 karma points
    Dec 06, 2018 @ 13:20
    Jannich Ibsen
    0

    Umbraco api controller, attribute route with name and backoffice

    Hi,

    I am trying to use attribute routing with umbraco api controller. Everything works until i want to give my route a name, like so:

    [RoutePrefix("api/sub/value")]
    public class ValueController : UmbracoApiController
    {
    
        [Route(Name = "GetValues")]
        public FormattedContentResult<string> Get()
        {
    
            return base.Content(HttpStatusCode.OK, "Content", new JsonMediaTypeFormatter());
        }
    }
    

    The route works quite well, however, when i try to log in to backoffice i am met with this:

    System.ArgumentException: A route named 'GetValues' is already in the route collection. Route names must be unique.
    Parameter name: name
       at System.Web.Routing.RouteCollection.Add(String name, RouteBase item)
       at System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.Add(String name, IHttpRoute route)
       at System.Web.Http.Routing.AttributeRoutingMapper.AddGenerationHooksForSubRoutes(HttpRouteCollection routeTable, IEnumerable`1 entries)
       at System.Web.Http.Routing.AttributeRoutingMapper.<>c__DisplayClass2.<MapAttributeRoutes>b__0(HttpConfiguration config)
       at System.Web.Http.HttpConfiguration.ApplyControllerSettings(HttpControllerSettings settings, HttpConfiguration configuration)
       at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
       at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
       at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
       at System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type)
       at System.Web.Http.Controllers.HttpControllerDescriptor..ctor(HttpConfiguration configuration, String controllerName, Type controllerType)
       at Umbraco.Web.Trees.ApplicationTreeExtensions.<TryGetRootNodeFromControllerTree>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Umbraco.Web.Trees.ApplicationTreeController.<GetRootForSingleAppTree>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Umbraco.Web.Trees.ApplicationTreeController.<GetApplicationTrees>d__0.MoveNext()<---
    

    An example can be found here:

    https://github.com/JannichIbsen/umbracoattributerouting

    It doesnt matter what i name the route, it always fails in backoffice.

    My question is, why is it double registered when i add the routename to me route attribute?

  • Frans de Jong 522 posts 1762 karma points c-trib
    Dec 07, 2018 @ 09:27
    Frans de Jong
    0

    I don't think this kind of routing is permitted by default. You can specify a area and a controllername for the apicontroller:

    https://our.umbraco.com/Documentation/Reference/Routing/WebApi/

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies