Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Why is PermanentLinkMapStore.ToMapped returning false?

Vote:
 

I'm trying to use 'ToPageDataCollection()' to get a list of links and add this to my repeater.
The problem is that the function 'PermanentLinkMapStore.ToMapped(url)' inside 'ToPageDataCollection' returns false.

More exactly this is not working:

var url = new UrlBuilder(linkItem.Href); // url is now {http://localhost.mysite.no/Big/House/}
PermanentLinkMapStore.ToMapped(url); // This returns false. Why?

This is the code I use to get link list and use it as a datasource for my repeater:

var relatedLinkItems = CurrentPage["shortcutList"] as LinkItemCollection;
var relatedLinkPages = relatedLinkItems.ToPageDataCollection();
relatedLinkPages = FilterForVisitor.Filter(relatedLinkPages);

var pages = FilterForVisitor.Filter(relatedLinkPages);
rptshortcutList.DataSource = pages;
rptshortcutList.DataBind();

 

#52871
Aug 18, 2011 11:10
Vote:
 

Could you post the code for ToPageDataCollection()?

#52874
Aug 18, 2011 12:10
Vote:
 

I thought that function was default EPiServer. Here it is:

 

    public static class LinkItemCollectionUtility
    {
        public static PageDataCollection ToPageDataCollection(this LinkItemCollection linkItemCollection)
        {
            var pageDataCollection = new PageDataCollection();
            foreach (var linkItem in linkItemCollection)
            {
                var url = new UrlBuilder(linkItem.Href);
                if (PermanentLinkMapStore.ToMapped(url))
                {
                    var page = DataFactory.Instance.GetPage(PermanentLinkUtility.GetPageReference(url));
                    if (page != null)
                    {
                        pageDataCollection.Add(page);
                    }
                }
            }
            return pageDataCollection;
        }
    }

 

#52875
Aug 18, 2011 12:18
Vote:
 

The code looks fine. Only way it should return false is for external links, e-mail address, documents etc. Are you sure this is an internal link?

#52876
Aug 18, 2011 12:25
Vote:
 

I'm debugging in Visual Studio and the URL is a object, where 'uri' is the above url.

#52893
Aug 18, 2011 12:45
Vote:
 

Yes, but since it is returning false EPiServer cannot find it in its database. Try readding the pages in the LinkItemCollection property in edit mode and see if that makes a difference.

#52894
Aug 18, 2011 12:53
Vote:
 

PermanentLinkMapStore is used to convert between the permanent link format (e.g. ~/link<guid>.aspx) to the "classic" format (e.g. /templates/pages/page.aspx?id=7).

In your example the url is in the FURL format, to get the page from that format you could instead of PermanentLinkMapStore use Global.UrlRewriteProvider.TryConvertToInternal. The second out parameter will in case of a match typically be the PageReference to the page.

#52895
Aug 18, 2011 13:06
* 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.