This project is read-only.

Proper routing usage

Topics: Administration, Core, Customizing Orchard
Apr 1, 2014 at 2:16 PM
I'm using route names for finding routes in some of my modules which broke when moved to the version 1.8.

The way I'm using route names is
Redirect(Url.RouteUrl("RouteNameDefinedInRoutes.cs", new { someKey = someValue }))
So I did some debugging and tried to find route by name with Url.RouteCollection["RouteNameDefinedInRoutes"] but it returned null, and now my question is what is the proper way of using route names in Orchard?
Apr 1, 2014 at 5:35 PM
i am having a similar issue after upgrading from 1.7.2 to 1.8 with web api.

This used to work in 1.7.2

I have defined a web api route provider :
   public class HttpRoutes : IHttpRouteProvider
        public void GetRoutes(ICollection<RouteDescriptor> routes)
            foreach (RouteDescriptor routeDescriptor in GetRoutes())

        public IEnumerable<RouteDescriptor> GetRoutes()
            return new[] {
            new HttpRouteDescriptor {
                Name = "DefaultApiWithAction",
                Priority = -10,
                RouteTemplate =  "api/{controller}/{action}/{id}",
                Defaults = new {
                    area = "Intelli.Area",id = RouteParameter.Optional
and then i call in code :
 var urlresource = UrlHelper.Link("DefaultApiWithAction", new { id = model.ID, action = "Get", controller = "Operations" }),
at this point i get an exception :
A route named 'DefaultApiWithAction' could not be found in the route collection. Parameter name: name
have been struggling all day to figure it out.

Apr 1, 2014 at 6:49 PM
Please file a bug, and in the meantime try not to use named routes. There has been some changes related to it, so I assume it is related. I will investigate.
Apr 1, 2014 at 7:06 PM
Sep 25, 2014 at 2:53 PM
Microsoft coused this issue. :)

rodpl and me find bug in RouteCollection class.

In orchard 1.7.3 when you add new route to routeCollection you use
_routeCollection.Add(...) method and it works fine.

but in > 1.8 you refactored RoutePublisher and try make it better by change Add to Insert method

Difference between Add and Insert cause issue.
Insert method doesen't add routeName to internal collection _namedMap.
When _namedMap doesn't have names then routeCollection returns null for every named route.

I hope It helps you to resolve issue.
Sep 26, 2014 at 2:34 PM
Oct 23, 2014 at 11:31 PM
I see that the pull request has been cancelled. Is there some reason this isn't going to be fixed? This is a major problem for us.