11

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.

2
  • i can help you about this but i need more details. how do you feed the slug, route, path, title properties for each content items ? if your problem is just about the "/" at the end, i'm sorry but I think you will have to deal with it. Anyway, you should really consider asking your issues on the official orchard forums where they (the official orchard team members) are really active : orchard.codeplex.com/discussions
    – Proviste
    Jun 27, 2011 at 14:54
  • Can you post your RouteProvider.cs?
    – mdm
    Jun 27, 2011 at 15:28

1 Answer 1

7

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?

4
  • Thanks pszmyd, but my route is still not activated with a priority of 11. It will catch on ~/newcastle/ for example, but not ~/newcastle which is the RoutePart.Path value for the content item. Am I doing something else wrong? I do have an AreaController that I use for my admin type screens, is this not a good idea you think?
    – Brendan
    Jun 28, 2011 at 1:19
  • Turns out 15 was the magic number. It would be good if the designer tools could tell you what route the current request was served by. Thanks pszmyd, props for your blog also, I have found it very useful.
    – Brendan
    Jun 28, 2011 at 3:24
  • @Brendan: Route Debugging is something that Orchard really needs. There is an open ticket at orchard.codeplex.com/workitem/17287 - the more votes it gets the better chance it has of getting implemented. @Pszmyd: You've written modules for nearly everything else conceivable why not this? :-p
    – mdm
    Jun 28, 2011 at 11:35
  • @Piotr i am having same problem.my route is hitting but it gives me access denied error.please help me. Nov 15, 2012 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.