How to Change URL to Admin Controls

Topics: Customizing Orchard
Dec 13, 2011 at 6:08 PM

Because we want to host a legacy admin site inside our new orchard site we were hoping it would be possible to change the URL used to access all admin functions. I thought it might be as copying from the StandardExtensionRouteProvider and modifying the code as below the below and then some extra cleanup but it doesn't seem to work at all. Am I on the right track or is it much more complex than I was imagining?

 

    public class Routes : IRouteProvider {
        
        private readonly ShellBlueprint _blueprint;
 
        public Routes(ShellBlueprint blueprint)
        {
            _blueprint = blueprint;
        }
 
        public void GetRoutes(ICollection<RouteDescriptor> routes) {
            foreach (var routeDescriptor in GetRoutes()) {
                routes.Add(routeDescriptor);
            }
        }
 
        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            var displayPathsPerArea = _blueprint.Controllers.GroupBy(
                x => x.AreaName,
                x => x.Feature.Descriptor.Extension.Path);
            var allRoutes = new List<RouteDescriptor>();
            foreach (var item in displayPathsPerArea)
            {
                var areaName = item.Key;
                var displayPath = item.Distinct().Single();
 
                allRoutes.Add(new RouteDescriptor {
                    Priority = 10,
                    Route = new Route("OrchardAdmin/" + displayPath + "/{action}/{id}"new RouteValueDictionary {
                        {"area", areaName},
                        {"controller""admin"},
                        {"action""index"},
                        {"id"""}
                    }, new RouteValueDictionary(), new RouteValueDictionary {
                        {"area", areaName}
                    }, new MvcRouteHandler())
                });
 
                
            }
 
            allRoutes.Add(new RouteDescriptor {
                Priority = 10,
                Route = new Route("OrchardAdmin/{action}/{id}"new RouteValueDictionary {
                    {"area""Orchard.Core.Dashboard.Controllers"},
                    {"controller""admin"},
                    {"action""index"},
                    {"id"""}
                }, new RouteValueDictionary(), new RouteValueDictionary {
                }, new MvcRouteHandler())
            });
            return allRoutes;
        }
    }
Coordinator
Dec 13, 2011 at 6:39 PM

IRouteProvider is what you want to use, but you just need to add your own route. Don't worry about the existing ones. In fact, I have a hard time understanding what you are trying to do here. The first thing to check is whether you atually need your own route at all or if the built-in ones would be enough.

Dec 13, 2011 at 6:43 PM

Basically I want to make all functions previously accessible via /Admin/foo instead accessible via /OrchardAdmin/foo. That way I can free up /Admin for a legacy app that expects to be on /Admin. The problem is those routes are built up dynamically from what I can tell.

Coordinator
Dec 13, 2011 at 6:46 PM

That won't work. You will break all kinds of things. Your legacy app will have to run somewhere else. In a different vdir for example.

Dec 13, 2011 at 7:39 PM

Good to know before I went too far down that path.