Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

orchard cms routing question

I have created some custom content types which include the route part so my content managers can edit the slugs for the items. I am having no luck configuring a route that will enable a controller of my own to serve requests for these items.

The route for paths to the ItemController in the core Routable module has a priority of 10. I have tried making a route that utilises an IRouteConstraint, similar to how the Blog module achieves what I want to do, with a lower priority but still no luck.

If I make my URLs end with a / then my custom route is activated, as then it does not match the path of my content items. This is not a desirable solution. I cannot understand why it won't discover my custom route ahead of the one belonging to the Routable module.

Any help would be greatly appreciated, many thanks in advance.

UPDATE:
Here is my GetRoutes method from my IRouteProvider implementation:

    public IEnumerable<RouteDescriptor> GetRoutes()
    {
        return new[] {
            new RouteDescriptor
            {
                Priority = 0,
                Route = new Route(
                    "Admin/Jugganort/{controller}/{action}/{id}",
                    new RouteValueDictionary {
                                                {"area", "Jugganort"},
                                                {"controller", "Area"},
                                                {"action", "List"}
                                            },
                    new RouteValueDictionary(),
                    new RouteValueDictionary {
                                                {"area", "Jugganort"}
                                            },
                    new MvcRouteHandler())
            },
            new RouteDescriptor
            {
                Priority = 9,
                Route = new Route(
                    "{location}/{merchant}/{promotion}",
                    new RouteValueDictionary {
                                                {"area", "Jugganort"},
                                                {"controller", "Home"},
                                                {"action", "Index"},
                                                {"merchant", UrlParameter.Optional},
                                                {"promotion", UrlParameter.Optional}
                                            },
                    new RouteValueDictionary { 
                        { "location", _routeConstraint }
                    },
                    new RouteValueDictionary {
                                                {"area", "Jugganort"}
                                            },
                    new MvcRouteHandler())
            }
        }; 
    }  

_routeConstraint is a simple implementation of IRouteConstraint that just looks for a hardcoded value of "newcastle" for the location in the route.

Is my understanding of the RoutePart not correct? Will those items always have to be served up from the Routable module's ItemController? Is my only option to user alternates to render custom shapes?

The orchard forums will be my next point of call. Thanks again for any help you may be able to provide.

like image 915
Brendan Avatar asked Jun 27 '11 12:06

Brendan


1 Answers

You can serve those items from your own controller too, sure. The only thing needed is a route that would reach your controller. Then, you can return pretty much anything you want:)

It looks like your URLs are being matched by some other route(s). If you want to override the default route and make sure your one would be compared first, you should specify a higher priority (eg. 11). The catch-all route in Orchard.Core.Routable.Routes has a priority of 10, so will catch even the URLs matching your routes.

You haven't provided a default value for id in the first route - that can also pose a problem. If you don't explicitly specify id in an URL, it won't be matched.

Btw, is Area a proper name for the default controller in the first route, or just a typo?

like image 132
Piotr Szmyd Avatar answered Oct 14 '22 23:10

Piotr Szmyd