SaaS CMS has officially launched! Learn more now.

Stuck in publishing loop


Essentially, I'm attaching to the publishing event like so

contentEvents.PublishedContent += MyMethodOnPublish;

then eventually saving my content like so

contentRepository.Save(editablePage, SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);

but then the event for the content keeps getting called in an infinite loop, which kinda makes sense but obviously is not the desired behaviour, is there a recommended method to prevent this publishing loop?

using CMS

Edited, Oct 30, 2019 11:28

Hi Noel

You don't need to save the content inside the event handler.

If you make any changes to the content being published, it will be saved right after your event handler. Unless you cancel the action, of course.

Oct 30, 2019 12:20

To be more cleare on what Stefan says,

You need attach to contentEvents.PublishingContent instead of contentEvents.PublishedContent

Then you can change the content, and don't need to call the save method again.

Oct 30, 2019 13:11

Thank you @Stefan and @Sebbe, yeah Stefan was mostly correct, except if using Published (instead of Publishing) then it complains about the properties being read-only.

Oct 30, 2019 13:13
Stefan Holm Olsen - Oct 30, 2019 13:22
Yeah. I mixed up those names when reading your post. Glad it works anyway.
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.