November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
By default when you register a custom route through MapContentRoute it will start route from SiteDefintion.Current.RootPage, that is the part of the url taken care of {node} starts from root. You can test this if you test url /test/start/inloggen/blabla it you get your page (given that your start page have urlsegment "start").
You can set the routing to start from another node than RootPage, I guess you want it to be from SiteDefintion.Current.StartPage, like:
var segmentRouter = ServiceLocator.Current.GetInstance<IUrlSegmentRouter>();
segmentRouter.RootResolver = (sd) => sd.StartPage;
var parameters = new MapContentRouteParameters()
{
UrlSegmentRouter = segmentRouter
};
RouteTable.Routes.MapContentRoute("customRoute",
"test/{node}/{partial}/{action}",
new {action = "index"},
parameters);
When I use MapSimpleAddressRoute, the /test/ url is working (it finds the HomePageController with the Index action) but /test/inloggen/blabla is not working.
I also thought it could have something to do with the language. I am using dutch as language so I tried this:
var a = new MapContentRouteParameters { StrictLanguageRoutingResolver = (Func<bool>)(() => false) };
routes.MapContentRoute("customRoute",
"test/{node}/{action}",
new { action = "index" }, a);
This is not working either
@Johan, that is the solution. I can not believe this is not documented anywhere. Thank you!
Glad it worked out. Regarding language, you could add a {lang} part to your url like e.g.:
"test/{lang}/{node}/{action}"
and then optionally have a default value for language like:
new { action = "index" , language = "en"}
(or dutch in your case)
Johan, I'm still having some trouble with some other routing issues. Maybe you could help me with them also if you would like that.
I would like to use the url /welcome/{id} in my website. I have a welcome page with an index action which is working when I call it like /welcome/index?id=1234 or /welcome?id=1234. I tried the following contentroute:
routes.MapContentRoute("customRoute",
"{node}/{id}",
new { action = "index", id = "1" },
parameters);
This is not working. Do you have any idea how I could fix this? I think it is strange that the /{id} is not working because I declared it in my route.
routes.MapContentRoute(
"default_node",
"{node}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
is also not working (404).
Ok, in this case I am not sure that you should use {node} at all.
{node} works so that it starts from the root of the route and then for each segment try to match the current segment with the urlsegment for the content. So if you have a route like "welcome/{node}/{action}/{id}" and a url like e.g. "/welcome/12" the node segment will start from RootPage and then look at it's children if there is any children with urlsegment "12". Since there is none it will set routed content to SiteDefinition.Current.RootPage and then leave the rest of the url for next part. So then "action" and "id" will be consumed as parameters but the content routed to is still SiteDefinition.Current.RootPage.
So in next step it will try to find a controller for SysRootPage (the type for RootPage) which it will not found and hence a 404 is returned.
Instead I think you could create a custom segment e.g. {id} as described http://joelabrahamsson.com/custom-routing-for-episerver-content/ (under section custom routing using a custom segment) .
So what you could do in your segment implementation is parse the id from the url and then set segmentContext.RoutedContentLink to the parsed value.
Hi, I got a very strange problem: routing to a content page is not working.
I read http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=65320, http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/10/EPiServer7--Routing/ and http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-CMS/75/Routing/Routing/ (btw the last one containers an error. It says in the code sample "MapPageRoute" but that method does not take the parameters url, defaults and name)
I just can't get it to work.
In my global.asax i override the RegisterRoutes method:
When I use the URL /inloggen/blabla i get the expected response. When I use /test/inloggen/blabla this is not working: i get a 404 message. I can't figure out what's wrong here.
Hope someone can help.