Please help with urgen routing problem

Vote:
 

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

For example: http://www.lernia.se/sok/jobb/

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:

http://www.lernia.se/utbildning/solna/fordonsteknik/

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!

#86459
May 22, 2014 7:59
Vote:
 

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

#86460
May 22, 2014 8:42
Vote:
 

I have now reported this as a bug

#86480
May 22, 2014 12:59
Vote:
 

Hi

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;

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



#87522
Jun 16, 2014 13:10
Vote:
 

Thanks Johan, that workaround did the trick!

#87526
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.