PartialRouter GetPartialVirtualPath not being called for outgoing links

For my current project I have a structure in the EPiServer that is different form my front-end urls.

In episerver the structure is:

Homepage

- artists

-- a_e

--- eminem : ArtistDetailPage

on the front-end the url will be something like www.acme-corp.com/artists/eminem/

In order to facilitate this I've created a class that implements the IPartialRouter

in the controller for the homepage I do something like: UrlResolver.Current.GetUrl(currentPage.HeaderPageLink);

where the HeaderPageLink is a pagereference to a artist detail page instance. The url that is returned is /artists/a_e/eminem/

What am I doing wrong?

#113041
Nov 11, 2014 14:34

I have the same problem, where GetPartialVirtualPath is never called.

I initialise the PartialRouter in an InitializableModule and then added it via RegisterPartialRouter(). I noticed that the number of Routes does not increase - so I am uncertain if this worked or if this is the right way to do this. 

Also the information about which is the correct way to get a URL from a ContentReference is very inconsistent - different blog posts give different methods that should be called - possibly in different use-cases, however many of these methods are now obsolete.

#113076
Nov 12, 2014 12:29

I just tried on an alloy site (running CMS.Core.7.16)  with following router:

 public class StandardPageRouter : IPartialRouter<PageData, StandardPage>
    {
        public PartialRouteData GetPartialVirtualPath(StandardPage content, string language, System.Web.Routing.RouteValueDictionary routeValues, System.Web.Routing.RequestContext requestContext)
        {
            return new PartialRouteData()
            {
                BasePathRoot = content.ContentLink,
                PartialVirtualPath = "partialrouted"
            };
        }

        public object RoutePartial(PageData content, EPiServer.Web.Routing.Segments.SegmentContext segmentContext)
        {
            var next = segmentContext.GetNextValue(segmentContext.RemainingPath);
            if (next.Next == "partialrouted")
            {
                segmentContext.RemainingPath = next.Remaining;
            }
            return content;
        }
    }

registered in an initalization module as:

 RouteTable.Routes.RegisterPartialRouter<PageData, StandardPage>(new StandardPageRouter());

and it generates outgoing links containing segment "partialrouted" for StandardPage instances as expected. And no there will not be any additional routes registered when a partial route is registered. A partial route extends existing routes containing the segment "{partial}".

Have you registered any other custom routes?? (except the partial ones)

#113135
Nov 13, 2014 17:55

Hi, 

Thanks for your response. I've first tried it in the alloy sample site and indeed it works. then i've gone back to my own solution and I have narrowed it down to the following route:

RouteTable.Routes.MapEnterpriseRoutes(
"default",
"{language}/{node}/{action}/{page}",
new { action = "index", page = UrlParameter.Optional },
new MapContentRouteParameters { Direction = SupportedDirection.Incoming });

I believe a colleage has added this previously to make sure ajax requests were processed in the correct locale. The order of registering the routes doesn't seem to have effect. Am I correct in assuming that partialrouters are always executed after other routes?

For now I have disabled the above route and instead are setting the culture for the thread myself which seems to be working.

#113207
Edited, Nov 14, 2014 17:19

Partial routing is added to a route through segment {partial} so to get pratial routing enabled for your registered route you should register it as:

RouteTable.Routes.MapEnterpriseRoutes(
"default",
"{language}/{node}/{partial}/{action}/{page}",
new { action = "index", page = UrlParameter.Optional },
new MapContentRouteParameters { Direction = SupportedDirection.Incoming });
#113210
Edited, Nov 14, 2014 22:49
* 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.