Routing not working

Vote:
 

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:

        protected override void RegisterRoutes(RouteCollection routes)
        {
            base.RegisterRoutes(routes);

            RouteTable.Routes.MapContentRoute("customRoute",
                            "test/{node}/{partial}/{action}",
                            new { action = "index" });

        }

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.

 

#84768
Apr 07, 2014 13:50
Vote:
 

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);

    

#84769
Apr 07, 2014 13:58
Bojan S. - Oct 13, 2021 15:04
Hello,

I use the latest Epi libraries and have registered custom routings for some pages types.

I'm struggling with the custom routing page links inside the RTE. After adding a "Page Link" inside RTE it works as expected on the first page publish.

If someone edits the same RTE content another time it hiddenly destroys all "page links" inside and moves the URLs as they were "External Link". So the editor doesn't know about this and saves the links with unresolvable links.

One example of the wrong external URL is: /EPiServer/CMS/Content/,,5/forening/ale/kontakt/?epieditmode=False

I notice the parts of this URL as "/EPiServer/CMS/Content/" (Epi's system path) + ",,5" (StartPage Id) + "/forening/ale/kontakt/" (custom routing which needs to be resolved)

My custom routed page isn't a direct child below StartPage but it belongs below it in a deeper structure.

I tried your example in a couple of ways but had no success.

Can you give me a hint on how to define MapContentRoute to recognize my custom routed pages?

Thanks
Vote:
 

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

 

#84770
Apr 07, 2014 14:00
Vote:
 

@Johan, that is the solution. I can not believe this is not documented anywhere. Thank you!

#84771
Apr 07, 2014 14:06
Vote:
 

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)

#84772
Edited, Apr 07, 2014 14:09
Vote:
 

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).

#84773
Apr 07, 2014 14:17
Vote:
 

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.

#84783
Apr 07, 2014 15:07
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.