Please help with urgen routing problem


We are using segment mapping on one customer to solve a that the user can send in what to search for.

For example:

To solve this we use this code:

public class SearchSegment : SegmentBase
        public SearchSegment(string name)
            : base(name)

        public override bool RouteDataMatch(SegmentContext context)
            if (context.LastConsumedFragment == "sok")
                var context2 = HttpContext.Current.Request;

                context.RouteData.Values.Add("action", "index");

                var next = context.GetNextValue(context.RemainingPath);

                if (next.Next == "jobb" || next.Next == "utbildning")
                    context.RouteData.Values.Add("selectedTab", next.Next);

                if (!string.IsNullOrWhiteSpace(context2.QueryString["searchterm"]))
                    context.RouteData.Values.Add("searchterm", context2.QueryString["searchterm"]);
                context.RemainingPath = string.Empty;
                return true;
            return false;

        public override string GetVirtualPathSegment(RequestContext requestContext,RouteValueDictionary values)
            return null;

The urgent problem we have after upgraded to tha latest version of EPiServer is that this always returns null: context.LastConsumedFragment 

This is the more simple segment routing we have, we also have another more complex where the user can type for example:

This will return all educations about fordonsteknik in solna and the way we solve that is that parsing through the RemainingPath but this does not work either since the first check on LastConsumedFragment is null.

I do not know how to solve this, so Please help!

May 22, 2014 7:59

A little more info:
context.RoutedContentLink is always 1 instead of the content routed

May 22, 2014 8:42

I have now reported this as a bug

May 22, 2014 12:59


This is caused by a changed behaviour (not intentional) that was introduced in 7.5 which is that a custom route by default starts from RootPage and not StartPage. You can specify explicitly where to start route as in code below. I have reported a bug that we should change the default behaviour for custom routes so they by default starts from Start page and not Root. However that is a breaking behaviour change (again...) so that needs to go into next major.

  public void Initialize(InitializationEngine context)
            var segment = new SearchSegment("search");

            var routingParameters = new MapContentRouteParameters()
                SegmentMappings = new Dictionary<string, ISegment>()
            routingParameters.SegmentMappings.Add("search", segment);

            var urlSegmentRouter = context.Locate.Advanced.GetInstance<IUrlSegmentRouter>();
            urlSegmentRouter.RootResolver = (s) => s.StartPage;
            routingParameters.UrlSegmentRouter = urlSegmentRouter;

              name: "searchterms",
              url: "{language}/{node}/{search}",
              defaults: new { action = "index" },
              parameters: routingParameters);

Jun 16, 2014 13:10

Thanks Johan, that workaround did the trick!

Jun 16, 2014 13:25
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.