SaaS CMS has officially launched! Learn more now.

Programmatically update the start page error

public ActionResult Index(ShippersPage currentPage)
            var startPage = _contentRepository.GetDefault<StartPage>(ContentReference.StartPage).CreateWritableClone() as StartPage;
            startPage.Shippers = currentPage.ContentLink;
            _contentRepository.Save(startPage, EPiServer.DataAccess.SaveAction.CheckOut, EPiServer.Security.AccessLevel.Edit);

            var model = new ShippersPageViewModel(currentPage);

            model.Shippers = _loader.GetChildren<ShipperPage>(currentPage.ContentLink);

            return View(model);

When i call .Save i get the error: 'Content type "StartPage" is not allowed to be created under parent of content type "StartPage"'

Im trying to update property on the StartPage but it wont let m e because it tries to create new page? I just wnat to update the existing one.

Sep 07, 2021 11:21

That looks correct. Are you sure there's not been any changes with page type restrictions with the structure of your site that would mean errors would occur when saving. You don't have a startpage under a startpage already?

Also you could try to change the SaveAction to SkipValidation

Sep 07, 2021 11:34

Make sure no AvailableContentTypes defined on the startpage

[AvailableContentTypes(Include = new[] {
public class SysRoot : PageData
Sep 07, 2021 12:18

You should use

var startPage = (StartPage)_contentRepository.Get<StartPage>(ContentReference.StartPage).CreateWritableClone();


var startPage = _contentRepository.GetDefault<StartPage>(ContentReference.StartPage);

GetDefault gives you a new instance, while Get gives you an existing instance. No need to call CreateWriteableClone() on the instance you get from GetDefault either, since it's already writeable.

Edited, Sep 07, 2021 20:44
Scott Reed - Sep 08, 2021 7:59
good spot, I totally glazed over that :p
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.