Copied to clipboard

Flag this post as spam?

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


  • Andrii 4 posts 105 karma points
    Jul 31, 2019 @ 07:49
    Andrii
    0

    Custom routes break umbraco backoffice

    Custom routes for custom non content pages break backoffice. When i add custom mvc or http routes to RouteTable - halph of backoffice start using /{myroute}/ for api, so it just produces 404 and simply not working. My code:

     [ComposeBefore(typeof(ServicesComposer))]
        public class UserComposer : IUserComposer
        {
            public void Compose(Composition composition)
            {
                composition.Components().Append<RouteComponent>();
                composition.Components().Append<BundleComponent>();
            }
        }
    
    public class RouteComponent : IComponent
        {
            public void Initialize()
            {
                RouteConfig.Register(RouteTable.Routes);
                //GlobalConfiguration.Configure(WebApiConfig.Register);
            }
    
            public void Terminate()
            {
                //throw new NotImplementedException();
            }
        }
    
    public static class RouteConfig
        {
            public static void Register(RouteCollection routes)
            {
                //routes.MapControllerAttributeRoutes()
    
                routes.MapRoute(
                  name: "Default",
                  url: "mvc/{controller}/{action}/{id}",
                  namespaces: new string[] { "XX.xxx.Controllers", "XX.xxx.Hijacking.Controllers" },
                  defaults: new
                  {
                      Controller = "CustomTour",
                      action = "Index",
                      id = UrlParameter.Optional
                  });
            }
        }
    

    I have added custom namespaces for routes, but umbraco just start using my route in backoffice and doesnt work anymore.

    any idea why it happens and how to solve? I cant use .MapUmbracoRoute as need custom MVC, not based on real content pages.

    Link to issue on Umbraco-CMS github: https://github.com/umbraco/Umbraco-CMS/issues/6045

  • Andrii 4 posts 105 karma points
    Aug 06, 2019 @ 07:36
    Andrii
    100

    Solution for this issue, got from support team:

    [ComposeAfter(WebFinalComposer)]
    public class RouteComposer : IComposer 
    { 
            public void Compose(Composition composition)
            {
                composition.Components().Append<RouteComponent>();
            }
    }
    

    or

    [ComposeAfter(typeof(WebFinalComposer))]
        public class RouteComposer: ComponentComposer<RouteComponent>
        {
        }
    

    where RouteComponent:

    public class RouteComponent : IComponent
        {
            public void Initialize()
            {
                RouteConfig.Register(RouteTable.Routes);
                GlobalConfiguration.Configure(WebApiConfig.Register);
            }
    
            public void Terminate()
            {            
            }
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft