Copied to clipboard

Flag this post as spam?

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

  • Dave de Moel 105 posts 479 karma points c-trib
    Mar 20, 2019 @ 09:37
    Dave de Moel

    Umbraco 8 enable attribute routing for api and Swagger

    See old post below.

    I have found a workaround to get attribute routing working via the following url: Umbraco git

    I have a problem with SwashBuckle. After installing it on the first run /swagger was working fine, but now I get the message: "No umbraco document matches the url '/swagger'.". I assume this has something to do with routing, but am unable to find a work around as of yet. Anyone already experience with implementing it in Umbraco 8?


    I have a problem getting Attribute Routing for api controllers working in Umbraco 8.

    As we have now switched from IApplicationEventHandler to Composers and Components it seems we have lost control of the order in witch configuration is intialized, resulting in unexpected behaviour.

    I currently have the following setup to enable attribute routing:

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    internal class CustomRoutingComposer : ComponentComposer<CustomRoutingComposer.CustomRoutingComponent>
        public class CustomRoutingComponent : IComponent
            public void Initialize()
            public void Terminate()

    When a first started up my application, this worked. The route was registered and all was well. However, I have noticed it is hit and miss because at the same time I often enounter the following error:

    <Error><Message>An error has occurred.</Message><ExceptionMessage>The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.</ExceptionMessage><ExceptionType>System.InvalidOperationException</ExceptionType><StackTrace>at System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes() at System.Web.Http.Routing.RouteCollectionRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)</StackTrace></Error>

    Adding *.EnsureInitialized() also doesn't work. It seems that there is no guarantee components are run in order and with the IApplicationEventHandler having been removed I am currently unsure as to how we should get attribute routing for api's working. Can anyone help me out here? :-(

Please Sign in or register to post replies

Write your reply to: