Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Anders Hattestad
Jan 28, 2011
(4 votes)

PageProviders and DDS, a match from heaven…

I’m working on a pet project where I’m trying to show community entities as a tree structure in EPiServer. image But then I tried to just show on structure bellow an other page using PageProviders.

To make a PageProvider you need both a unique number inside the page provider, and a guid that is unique across all elements. This is a perfect match with the DSS’s  Identity that both have a long and a guid inside.

So what I did was that I made myself a mapping table using the DDS Id as the id and guid for my page provider.

The properties in my DDS table is this:






and my episerver.config have these elements defined. Where should we get the page structure from, and where should they be displayed

Code Snippet
  1. <pageProvider>
  2.   <providers>
  3.       <add name="Club1" type="Itera.PageProviders.SubStructurPageProvider, EPiServer.Templates.RelatePlus"
  4.         entryPoint="43"
  5.           GetChildrenFrom="6"/>
  6.   </providers>
  7. </pageProvider>

The first method I need to implement is the one that returns page references for one page reference.

Code Snippet
  1. protected override PageReferenceCollection GetChildrenReferences(PageReference pageLink, string languageID)
  2. {
  3.     if (pageLink.CompareToIgnoreWorkID(base.EntryPoint))
  4.     {
  5.         var pages = EPiServer.DataFactory.Instance.GetChildren(GetChildrenFrom,
  6.             new LanguageSelector(languageID));
  7.         return SubStructurIDs.Ensure(pages, ProviderKey, pageLink.ToString());
  8.     }
  9.     else
  10.     {
  11.         var item = SubStructurIDs.GetItem(pageLink, ProviderKey);
  12.         if (item != null)
  13.         {
  14.             var pages = EPiServer.DataFactory.Instance.GetChildren(item.ContentPage,
  15.                 new LanguageSelector(languageID));
  16.             return SubStructurIDs.Ensure(pages, ProviderKey, pageLink.ToString());
  17.         }
  18.     }
  19.     return new PageReferenceCollection();
  20. }

I call the Ensure method and that stores the page references using the DDS. And the use the Id in the DDS table to make the “new” page link.

Code Snippet
  1. public static PageReferenceCollection Ensure(PageDataCollection pages, string providerKey,string parentPageLink)
  2. {
  3.     PageReferenceCollection result = new PageReferenceCollection();
  5.     var query = from item in Store.Items<SubStructurIDs>() where
  6.                     item.ProviderKey == providerKey &&
  7.                     item.ParentPageLink == parentPageLink
  8.                 select item;
  9.     var hash = new Dictionary<int, SubStructurIDs>();
  10.     foreach (var item in query)
  11.     {
  12.         hash.Add(item.ContentPage.ID, item);
  13.     }
  14.     foreach (var page in pages)
  15.     {
  17.         if (hash.ContainsKey(page.PageLink.ID))
  18.         {
  19.             result.Add(hash[page.PageLink.ID].ThisPageLink);
  20.             hash.Remove(page.PageLink.ID);
  21.         }
  22.         else
  23.         {
  24.             var newItem = new SubStructurIDs();
  25.             newItem.ContentPage = page.PageLink;
  27.             newItem.ParentPageLink = parentPageLink;
  28.             newItem.ProviderKey = providerKey;
  29.             Store.Save(newItem);
  30.             result.Add(newItem.ThisPageLink);
  32.         }
  33.     }
  34.     if (hash.Count > 0)
  35.     {
  36.         //Need to delete, or in other lang
  37.     }
  38.     return result;
  39. }


The I need to implement 2 functions, one where we have the page link and the find the guid, and one that have the guid and needs to find the page Link. These to are pretty much alike, and one looks like this

Code Snippet
  1. protected override Uri ResolveLocalPage(Guid pageGuid, out PageReference pageLink)
  2. {
  3.     var item = SubStructurIDs.GetItem(pageGuid, ProviderKey);
  4.      if (item != null)
  5.      {
  6.          pageLink = item.ThisPageLink;
  7.          return CreateUri(pageLink, item);
  8.      }
  9.      pageLink = PageReference.EmptyReference;
  10.      return null;
  11. }

Then we need to return a page

Code Snippet
  1. protected override PageData GetLocalPage(PageReference pageLink, ILanguageSelector languageSelector)
  2. {
  3.      var item = SubStructurIDs.GetItem(pageLink, ProviderKey);
  4.      if (item != null)
  5.      {
  6.          PageData org = EPiServer.DataFactory.Instance.GetPage(item.ContentPage, languageSelector);
  7.          if (org != null)
  8.          {
  9.              org = org.CreateWritableClone();
  10.              org.PageLink = pageLink;
  11.              org.ParentLink = PageReference.Parse(item.ParentPageLink);
  12.              org.PageGuid = item.Id.ExternalId;
  13.              return org;
  14.          }
  15.      }
  16.      return null;
  17. }

And then we are good to go.

Full code here

Jan 28, 2011


Mattias Minerbi
Mattias Minerbi Jan 16, 2013 12:20 PM

First of all, thanks for sharing this code!
I wonder..... lets say you have "segment A" that you want to copy (get all children from) and put it in different places in your epi-tree (multiple entry points, in my case a lot of places) is it possible to set entry points programmaticly in some way?
Will this solution work well with cached elements etc i.e lets say I update a page from my 'segment A' will that page will be updated for all places (every entry points).
It would be nice if a user could create a page in the epi-tree which has a page property that points out where to fetch data from and render that page and all children from current place in the epi-tree structure.... is that possible with this solution

Thanks in advance!

Anders Hattestad
Anders Hattestad Jan 16, 2013 05:47 PM

Hi, to add this code is needed:

var provider = new SubStructurPageProvider();
var config = new NameValueCollection();
config.Add("entryPoint", EPiPageStart.ToString());
config.Add("name", ProviderKey);
config.Add("GetChildrenFrom", "244");
provider.Initialize(ProviderKey, config);

To remove this code:

Have made myself a edit plugin that enables me to mount pages bellow me
mail me at if you want the code

Please login to comment.
Latest blogs
Stop Managing Humans in Your CMS

Too many times, a content management system becomes a people management system. Meaning, an organization uses the CMS to manage all the information...

Deane Barker | Nov 30, 2023

A day in the life of an Optimizely Developer - Optimizely CMS 12: The advantages and considerations when exploring an upgrade

GRAHAM CARR - LEAD .NET DEVELOPER, 28 Nov 2023 In 2022, Optimizely released CMS 12 as part of its ongoing evolution of the platform to help provide...

Graham Carr | Nov 28, 2023

A day in the life of an Optimizely Developer - OptiUKNorth Meetup January 2024

It's time for another UK North Optimizely meet up! After the success of the last one, Ibrar Hussain (26) and Paul Gruffydd (Kin + Carta) will be...

Graham Carr | Nov 28, 2023

Publish content to Optimizely CMS using a custom GPT from OpenAI 🤖

Do you find the traditional editor interface complicated and cluttered? Would you like an editorial AI assistant you can chat with? You can!

Tomas Hensrud Gulla | Nov 28, 2023 | Syndicated blog