Issue when both language branches of a page have the same url


We're using EpiServer 7 Patch 3 and we're trying to use cookies instead of url designators (/en/ or ?epslanguage=en) to store visitors' language preference. We found that EpiServer's routing logic fails to take the language cookie into account when multiple versions of a page have the same url.
For example: page X is available in both en (English) and da (Danish) via the urls:
- en: /Test/
- da: /Test/
The URL http://domain/Test/ would always return English even when the cookie epslanguage is set to da.

Looking at the routing logics through a decompiler led me to believe that this line in ResolveContentForIncoming() from EPiServer.Web.Routing.Segments.DefaultUrlSegmentRouter
was responsible:

content = (this._routingSegmentLoader.GetRoutingSegments(current.ContentLink, null).FirstOrDefault((IRoutable r) => string.Equals(r.RouteSegment, urlSegment, StringComparison.OrdinalIgnoreCase)) as IContent);

The call to GetRoutingSegments() returns all the language branches but it did not prioritize the list in any way. The subsequent call to FirstOrDefault() simply takes the first branch which might or might not match the visitor's current language.
We're working around this bug by injecting in our custom IUrlSegmentRouter via IoC (subclassing DefaultUrlSegmentRouter). In our code, we sort the results from GetRoutingSegments so that the branch corresponding to the prefered language would come up top.

Please advice if this is the correct approach (we've not encountered anything weird so far, but who knows :).

And I've just noticed issue#90086 in Patch 4 which sounds similar from the description. Can anyone confirm that the patch fixes this same issue?

Oct 23, 2013 12:11

How about hooking into the UrlRewriteProvider to one of the Convert to Internal events. And let the epslanguage query come from the cookie instead of the url segment?

Oct 23, 2013 13:30
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.