Try our conversational search powered by Generative AI!

Trouble understanding partial route and SegmentContext

Vote:
 

Hi, there,

I am trying to fix a problem that arose on my site when I upgraded from 7.11 to 8.9. The consultants who built the site created a partial routers for four of the custom content types that they created. Everything works except for one.

After carefully stepping through the code, I found that it seems like the system finds the page, but at the very last call it loses its info and then returns "Page Not Found".

While reading the documentation, blog entries, and forum posts, I keep running into code that looks like this, which my system also has something similiar

        public object RoutePartial(CarDetailsPage content, SegmentContext segmentContext)
        {
            //Expected format is RegNumber/
            var regNumber = segmentContext.GetNextValue(segmentContext.RemainingPath);
            if (!String.IsNullOrEmpty(regNumber.Next))
            {
 
                segmentContext.SetCustomRouteData();
                return content;
 
            }
 
            return null;
        }

I understand the return of content or null. What I don't understand is why segmentContext is being updated. Is segmentContext part of the content object?  Is it a reference to some global property?

#144481
Feb 13, 2016 0:13
Vote:
 

I found this blog that more or less explains what is supposed to happen. I still don't understand the mechanism.

http://joelabrahamsson.com/custom-routing-for-episerver-content/

Another question. A single request for a page goes through it sevent times. That is not normal, is it?

#144482
Feb 13, 2016 0:28
Vote:
 

A single request for a page normally generates a bunch of calls to routing for images etc that are loaded as a result of the first call. So nothing strange with that.

SegmentContext contains the url divided into segments and makes it easy to parse the url basically. It contains the part of the url that hasn't yet been matched basically. It will start from the left and match the language segment /en/ then that will be removed from SegmentContext since it's been dealt with. Next next finish :)

#144483
Feb 13, 2016 0:55
Vote:
 

Thanks! I have stepped through the code again, and was able to see what you described.

Now I think the error is happening at some point after the router returns. Do you know where the partial router returns too? It is not hitting the controller. And that doesn't really make sense. So I guess there is some other process before it actually routes to the controller?

#144486
Feb 13, 2016 1:22
Vote:
 

First it will parse the url using the SegmentContext etc and store the results in routedata, like what language and content to use. Next step is using the controller and using the parsed info from route data to create an instance of current page and send that to the correct controller as a parameter. Tried to insert some logging on the remaining path value? 

#144488
Feb 13, 2016 9:13
Vote:
 

Add some logging to make sure you are actually hitting that partial router and to check value on that url segment. I don't see you sending that route value for regNumber? Maybe add that to route data? Normally you also set the SegmentContext remaning path to what's left to take care of. 

#144489
Feb 13, 2016 9:33
Vote:
 

Thanks so much! It may be breaking when it tries to create the instance of the current page and before it sends it to the correct controller.  I will further investigate.

#144635
Feb 16, 2016 14:17
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.