Restricting the Episerver Page Types available on the root page

In order to make content editors lives a lot easier, it’s a good idea to restrict the pages that they can create.  This is done using the [AvailableContentType] attribute, on top of your page type definition, if you added the following code then content editors would only be allowed to create child pages of type start page… simple

[AvailableContentTypes(Include = new[] { typeof(StartPage) })]

In every Episerver website your navigation hierarchy will always start from the Root page:

syspage

As the root page is an Episerver system type by default, we can’t apply the [AvailableContentType] attribute on it so content editors can create any page they want.  This can make life a bit nasty and I’ve personally seen a lot of navigation trees get very messy, very quickly.  Ideally, you want to limit the root page to have a start page, a container page and maybe a root page.  Luckily there is a way to override the default root page and create our own ones.

If you create a page called SysRoot that inherits from PageData, you inject your own propertie into the system root, the code looks something like this:

[ContentType(GUID = "3415B788-8359-4BF0-9375-2FE9BA90719B",
AvailableInEditMode = false)]
[AvailableContentTypes(Include = new[] {
typeof(StartPage),
typeof(ContainerPage))]
public class SysRoot : PageData
{
}

That’s it.. we have now restricted our pages 🙂

Conclusion

In today’s guide we’ve talked about the benefits of the types of child pages content editors can create for a more usable back-end.  As the root page of any Episerver site is the beginning of the page hierarchy, then this is the page we need to do something to.  Luckily, Episerver provides a way to override the system behaviour by creating a page called sysroot that implements page data

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

2 replies
  1. Tony
    Tony says:

    This did not work for me. I’m using Epi 7.5. I created a page model called SysRoot.cs under Models > Pages and it has exactly what your article says to have except instead of where you have StartPage, I have HomePage – which is the page type of my home page. After I build and try to add a page to the Root page, it still shows every page type created. Do you have any thoughts?

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *