Try our conversational search powered by Generative AI!

Custom IContent in AvailableContentTypes list on pages is removed on admin changes



[AvailableContentTypes(Availability.Specific, Include = new[] { typeof(ReactionLike), typeof(ReactionComment), typeof(NewsListPage.NewsListPage) })]
public class NewsPage : PageData

When someone do changes in for the PageType in admin, the ReactionLike and ReactionComment that is IContent implementations is no longer possible to create programmatically under NewsPage.

In our case they changed Sort Index and set the Stop Publish Date to 90 days.

What happens when we are trying to save an ReactionLike on a NewsPage:

EPiServer.Core.EPiServerException: Content type "ReactionLike" is not allowed to be created under parent of content type "NewsPage"
   at EPiServer.Core.Internal.DefaultContentRepository.ValidateContentTypeAvailability(IContent content)
   at EPiServer.Core.Internal.DefaultContentRepository.Save(IContent content, SaveAction action, AccessLevel access)

It's probably because that these isn't listed in admin and therefore isn't posted as selections when pressing save-button and update the settings for the PageType.

Possible solutions:

  • list the special types too
  • add special types as hidden inputs or something and include in post, so they aren't removed without possibility to add them again.

We could consider setting sensible defaults in code and re-deploy, but that isn't a solid solution for this problem.

The only sensible fix is that EPiServer UI won't mess up what is defined in code and still allow these changes when the customer feels they want to do changes themselves.

This happens a couple of times a year, probably because we "fix" it by resetting to defaults, and they go and re-add their changes again, so it is really an annoying and a very nasty bug...

Edited, Apr 13, 2021 8:53

I would also accept a way to make some of them forced.

Consider adding:

[ForcedContentTypes(Include = new[] { typeof(ReactionLike), typeof(ReactionComment) })]

Then they save event could iterate these and ensure they are present.

Apr 13, 2021 9:01

Or just extending the current attribute with a new property.

[AvailableContentTypes(Availability.Specific, Include = new[] { typeof(NewsListPage.NewsListPage) }, Forced = new[] { typeof(ReactionLike), typeof(ReactionComment) })]
Apr 13, 2021 9:06

Could you not change the types to inherit PageData and then hide the property with overrides so they appear in the admin. You'd end up with similar results without the issues. Usually when you want Container items in the tree you create them from PageData without any MVC rendering.

Apr 13, 2021 14:17

You mean use AvailableInEditMode=false?

Wouldn't these pages be visible in page tree too then? We don't want that.

I understand that this is a possible solution, but still, this seems like a Admin/UI bug anyway, since it's possible to code like this, and in some cases this is a viable solution, but the "save"-button messes things up. So ideally hidden inputs instead of checkboxes for IContent that is not PageData — and ensure these remains as available — seems like the simplest fix.

Apr 13, 2021 17:45

The pages would only be availiable in edit mode in places you've said they are allowed. All page types should be restricted, so if you don't allow them they won't be in edit mode but will still appear in the admin. It's just a idea for your immediate problem

Apr 13, 2021 20:46

So you mean if I have 10 instances of the PageData under a NewsPage it won't show in the Page Tree if it has AvailableInEditMode=false? Good to know. I mostly used that on local blocks, so that part (on PageData) is not tested by me...

Apr 13, 2021 21:18

BTW, our current "fix" is setting "allow all", so they can have archive settings and functionality at the same time, and awaiting fix in EPiServer... Noticing them that we have "opened up" those restrictions for the moment.

Apr 14, 2021 6:01

I think maybe we're talking at cross purposes. When you said availible in the page tree I thought you meant for the creation dialogue not in the actual page tree view. It sounds like you've got it handled with a fix so hopefully Episerver will come up with a solution. I'm not aware of anything being hidden if it's AvailibleInEditMode=false

Apr 14, 2021 9:29


Changed that part I think you misunderstood.

When someone do changes in for the PageType in admin, the ReactionLike and ReactionComment that is IContent implementations is no longer possible to create programmatically under NewsPage.

Apr 14, 2021 17:52
* 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.