The general link field was on a datasource item, and was linking to another page on the site (ie using "Insert link" rather than "Insert external link" to create an internal link). This current project is using Glass Mapper (which I think distracted me a bit) and the
Link.Url
proprty was empty. I thought maybe the field was being mapped incorrectly, but it all looked ok. I tried grabbing the link field on the datasource Item directly (LinkField)RenderingContext.Current.Rendering.Item.Fields["MyLinkField"]
and found that the InternalPath
field was empty, and the TargetItem
was null, even though the TargetID
field was populated with the correct ID of the linked page.Long story short, after digging through the code used to generate the URL I realised the
Sitecore.Context.Database.GetItem("linkedItemId")
was returning null, even though I could see the item in the Sitecore content editor. Shortly thereafter it hit me: when would the context database return null for an item that obviously exists? When the current user doesn't have access to it! Yep that's right, the linked page had anonymous read access disabled, so that even though a link can be created by an author, the end user can see a link but cannot see the item and therefore the URL cannot be generated.Moral of the story: if you can't get/see the link to an item, check the security and access permissions on that item!
No comments:
Post a Comment