0

I ran into some weird behavior in Glass Mapper on a recent project, and I wonder if anyone has any insights. I’m tasked with upgrading Sitecore from 8.1 (rev. 160519) to 8.2 Update 7 (the latest 8.x version). When the upgrade was complete, I ran into the general link field error mentioned in this article. So I installed the hotfix and got the site up.

When I tested I ran into a peculiar issue with Glass Mapper. Normal links throughout the site work fine, except for those using Glass’s RenderLink or BeginRenderLink. There, for pages located under the \sitecore\Content\Client\home location it’s carving off the initial \home (so a link to \sitecore\Content\Client\home\students would render as \students instead of \home\students).

However, the Sitecore LinkManager works just fine, and the glass code appears to use LinkManager.

I did this in a view to verify:

 @{
                var id = Guid.Parse("{74466305-2BB4-44D2-9860-57E35DC970E7}"); // the ID of a link that wasn’t rendering correctly.
                var item = SitecoreContext.GetItem<Sitecore.Data.Items.Item>(id);
                var sitecoreLink = Sitecore.Links.LinkManager.GetItemUrl(item); //using Sitecore’s link gets me the correct /home/student/application
                var glassLink = RenderLink(m => m.CompleteApplication); //this comes back as /student/application
       }

My initial thought was Glass was confusing \sitecore\Content\Client\home with \sitecore\Content\Home, but renaming the node and rebuilding the link database didn’t fix anything.

I’ve tried several different versions of the 4.x Glass Mapper with no difference. I’ve started to debug through the Glass Mapper code, but that’s slow going.

Does anyone have any thoughts?

Danimal
  • 7,672
  • 8
  • 47
  • 57

1 Answers1

0

The Glass link in V4 is generated when the model gets created. It is likely that the model was generated under a different Site context (Sitecore.Context.Site).

To test get Glass to load the model in your view above and then get the URL, this will ensure that both URLs are generated in the same site context. If it is different site contexts the you will need to see where and how the site context is being switched.

Michael Edwards
  • 6,308
  • 6
  • 44
  • 75
  • Unfortunately that didn't do it. Same result. I even went through and upgraded to Glass 5 and I get the same result. – Danimal Aug 01 '19 at 17:59