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);
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?
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?
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 :)
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?
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?
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.
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.