November Happy Hour will be moved to Thursday December 5th.

Catalog Content reverted to hierarchical URLs everywhere referenced

Vote:
 

Hi

We have implementation that should use SEO URLs for Catalog content everywhere they are referenced on the site, for example on the top navigation. However, recently all those links switched to hierarchical URLs. Client claims they were seeing SEO URLs previously in all those places and a recent deployment caused this change. We reverted this deployment on local and still see hierarchical URLs only.

Please advice on what could possibly cause this change and how we can fix it.

#228924
Edited, Oct 05, 2020 18:58
Vote:
 

How do you register HierarchicalCatalogPartialRouter ?

#228928
Oct 05, 2020 20:54
Vote:
 

Hey Quan

This is our code :

var commerceRootContent = contentLoader.Get<EPiServer.Commerce.Catalog.ContentTypes.CatalogContentBase>(referenceConverter.GetRootLink());
var hierarchicalCatalogPartialRouter = new HierarchicalCatalogPartialRouter(() => SiteDefinition.Current.StartPage, commerceRootContent, true);
RouteTable.Routes.RegisterPartialRouter(hierarchicalCatalogPartialRouter);

#228931
Oct 05, 2020 21:07
Vote:
 

Hi Quan

Any insight here?

#229014
Oct 06, 2020 20:04
Vote:
 

It looks correct. However I'd suggest to use Find all references feature in Visual Studio to check you are not using it anywhere else 

#229016
Oct 06, 2020 21:15
Vote:
 

Hey Quan

Checked. This is the only reference :

To add more context, the SEO URL is also working, but the catalog content, epecially categories in top nav of the site, initially showed SEO URL when you hover over the link or click on it. Now they show the heirarchical URL instead. We are trying to identify what could have caused this switch.

#229018
Oct 06, 2020 21:47
Vote:
 

Also search for CatalogRouteHelper - it might call MapDefaultHierarchialRouter which uses HierarchicalCatalogPartialRouter under the hood 

#229064
Oct 07, 2020 10:47
Vote:
 

Hey Quan

We are not calling CatalogRouteHelper anywhere in the solution :

#229077
Oct 07, 2020 13:01
Vote:
 

Hi Quan, would you please review the above and advise on next steps forward? 

#229171
Oct 08, 2020 12:50
Vote:
 

So nothing obvious from the code. I haven't used it myself but I believe you can use https://github.com/episerver/DeveloperTools to see which routers have been registered. With a bit of custom code and debugging you might be able to look into the setting used for HierarchicalCatalogPartialRouter. This goes far out of scope for a forum post and you might need to contact developer support services for further assistance

#229172
Oct 08, 2020 12:57
Vote:
 

Hey Quan

I got the Developer tools and when I lookup the route related to my category page, it highlighted this :

http://localhost/products/Curriculum

Can you help me understand what this means? Or you think I should open a support ticket?

#229385
Oct 13, 2020 20:19
Vote:
 

Hi Quan, is there any further information you can provide on Ritu's findings above? Please confirm at your earliest conveneince.  

#229428
Oct 14, 2020 20:27
Vote:
 

Good morning Quan, can we expect an update on this today 10/15? Please confirm.  

#229467
Oct 15, 2020 13:32
Vote:
 

Hi, unfortunately no, can't spot anything from the screenshot. It's not clear to me if that is all of the routers you have. As I said you might want to contact developer support service for further assistance.

@John: It might be good to know this is a "community" forum and you are not guaranteed help - it's the support service for. Even though I'm an Episerver employee and I try my best to help, posting in this forum is voluntary and it will be of lower priority if I have other works coming my way.

#229470
Oct 15, 2020 14:24
Vote:
 

Hi Quan

I reached out to Epi support and when I shared code snippets there to get feedback, they routed me back to Forums. I'm hoping you can shed some light here. This is what I shared with Support :

Since the default enableSEOOutgoingURL = true and CatalogRouteHelper.SetupSeoUriPermanentRedirect() approach does not work for me, I finally decided to take the approach that was recommended to switch from SEO to Hierarchical URL, by registering the RoutedContent event. And started putting some logic from RedirectToSeoUri here for troubleshooting. What I noticed was this :

 

My page hierarchical url : http://localhost/products/Curriculum

SEO URL : http://localhost/Curriculum

 

When I debug the highlighted code bit from RedirectToSeoUri()  below :

 

ISearchEngineInformation engineInformation = routedObject as ISearchEngineInformation;

      if (engineInformation != null)

        str = engineInformation.SeoUri;

      if (e.RoutingSegmentContext.ContextMode != ContextMode.Default || routedObject == null || string.IsNullOrEmpty(str))

        return;

      VirtualPathData virtualPath = this._urlResolver.GetVirtualPath(routedObject.ContentLink, routingSegmentContext.ContentLanguage, routingSegmentContext.RouteData.Values, (System.Web.Routing.RequestContext) null);

      string url = virtualPath.GetUrl();

      if (virtualPath == null || HttpContext.Current != null && HttpContext.Current.Request.Url.AbsolutePath.Equals(VirtualPathUtility.ToAbsolute(url), StringComparison.OrdinalIgnoreCase))

        return;

 

I see both HttpContext.Current.Request.Url and url point to my hierarchical page url, and thus simply return after this if condition and don’t actually do this :

 

routingSegmentContext.PermanentRedirect(url);

 

Which explains why the out of the box seo url approach is not working. I want to understand why this is the case? Was this a bug in this version of Episerver.Commerce? This is version 12.15.0. Or is there something wrong on our end which we are missing?

 

After this, I skipped the above and finally came up with this logic on the RoutedContent event that I registered :

 

private static void Routed_SeoUri(object sender, RoutingEventArgs e)

        {

            var context = e.RoutingSegmentContext;

            //RoutedObject is supposed to not be null here

            if (!(context.RoutedObject is CatalogContentBase))

            {

                return;

            }

 

            if (string.IsNullOrEmpty(context.LastConsumedFragment))

            {

                var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();

                string seoUrl = "";

                ISearchEngineInformation engineInformation = context.RoutedObject as ISearchEngineInformation;

                if (engineInformation != null)

                    seoUrl = engineInformation.SeoUri;

 

                if (!string.IsNullOrEmpty(seoUrl))

                {

                    //context.RouteData.Values.Remove(RoutingConstants.NodeKey);

                    var BasePathRoot = ContentReference.IsNullOrEmpty((ContentReference)ContentReference.StartPage) ?

                        (ContentReference)ContentReference.RootPage : (ContentReference)ContentReference.StartPage;

                    var baseURL = urlResolver.GetUrl(BasePathRoot);

                    var finalurl = baseURL + seoUrl;

                    //add qs if any

                    if(context.QueryString.HasKeys())

                    {

                        var qs = context.RequestUrl.ToString().Split('?')[1];

                        finalurl = finalurl + "?" + qs;

                    }

                    else

                    {

                        //check for original request type and form parameters

                        var originalMethod = HttpContext.Current.Request.RequestType;

                        if(originalMethod.Equals("POST"))

                        {

                            return;

                        }

 

                    }

                    context.TemporaryRedirect(finalurl);

                }

                else

                    return;

            }

        }

 

This works, but 1.) there seems to be a performance impact on every page load and 2.) this feels like a dirty fix for something that should work out of the box. Please review and provide feedback on the following :

  1. Why the out of the box approach doesn’t work in our case?
  2. Was there a bug related to this in Episerver.Commerce version 12.15? Was it fixed? If so, which version?
  3. Is my RoutedContent event approach an apt fix for this issue? Can it be improved? Or is there another way to approach this?
#229744
Oct 22, 2020 13:17
Vote:
 

Hi Quan

I really need some expert guidance on above. Can you please review it once and let me know your thoughts?

Regards

Ritu

#229905
Oct 26, 2020 16:12
Vote:
 

Hey Ritu and John,

As Quan previously answered, it is best if you contact Episerver Support (support@episerver.com) for the issues you are facing.

#229906
Oct 26, 2020 17:29
Ritu Madan - Oct 26, 2020 17:34
Thanks Chris! We did reach out to Epi Support and they routed us back here saying they can't really help us with complex technical queries.

Anyhow, we found the issue itself. We had introduced a third party integration using their dll and it seems that broke the SEO URLs. I'm thinking because they probably have the HierarchicalCatalogPartialRouter registered in their code as well, with SEO URL flag set to false. We've asked them to confirm and correct.
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.