Our monthly Virtual Happy Hour is happening this week, Fri Feb 23!

Try our conversational search powered by Generative AI!

Don't automatically remove thrashed content that is still referenced


Today we've encountered an EPiServer Find error which created 404 errors on certain areas of our site.
This was caused because a user thrashed a few pages which were still referenced by a few products in EPiServer Commerse.

I don't think EPiServer should automatically remove content that is still referenced and should either log Errors or Warnings when the automatic thrash job is ran.
Because now if at any point a user makes an error and the job is ran, the site is compromised.

Nov 06, 2017 13:18

In the version of Episerver CMS that I use, when an editor clicks Move to trash, they get notified "Any incoming links on the web to this page will not work after you move it to the trash." 
Are you saying that this warning is not adequate?
Or are you saying that editors should not be permitted to delete content?

Nov 06, 2017 22:25

I understand that users get this notification, but humans make errors and I think having an automated job that knows no context shouldn't be responsible for permanently deleting this kind of content.

I'd like to see a warning so an admin or a developer can make an educated desiscion whether or not this content can be deleted permanently.

Nov 07, 2017 9:35

Just prevent editors from moving referenced content to the trash like this

    public class PreventDeletingContentInitialization : IInitializableModule
        private IContentEvents events;

        private IContentRepository repository;

        public void Initialize(InitializationEngine context)
            this.events = context.Locate.Advanced.GetInstance<IContentEvents>();
            this.repository = context.Locate.Advanced.GetInstance<IContentRepository>();

            this.events.MovingContent += this.MovingContentToTrash;

        public void Uninitialize(InitializationEngine context)
            this.events.MovingContent -= this.MovingContentToTrash;

        private void MovingContentToTrash(object sender, ContentEventArgs e)
            List<ReferenceInformation> references = this.repository.GetReferencesToContent(
                contentLink: e.Content.ContentLink,
                includeDecendents: true).ToList();

            if (!references.Any() || e.TargetLink.ID != 2)

            e.CancelAction = true;
            e.CancelReason = "Deleting this content is not allowed, because it is still referenced.";
Nov 07, 2017 10:44

When a page is deleted, the change is not permanent. The page is moved to the trash container and can be restored by an authorized user.

Further, to prevent users from deleting content, remove their access rights to do that. Only give administrators permission to delete content.

Nov 07, 2017 18:27
This thread is locked and should be used for reference only.
* 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.