Musielak Marek

Posted on Friday, June 18, 2010 by Marek Musielak

How to determine who deleted the page in EPiServer

Couple of days ago a colleague of mine was looking for a way to determine who moved a page to the recycle bin in EPiServer. Much to my surprise, there is no way to find that out using EPiServer edit / admin mode.

I had been sure that when one moves the page to the recycle bin, the new version is created, but it turned out that there is no single trace who deleted the page. That's why I wrote the code below:


using System;
using System;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAccess;

namespace Web
{
public class Global : EPiServer.Global
{
protected void Application_Start(Object sender, EventArgs e)
{
DataFactory.Instance.MovedPage += SaveNewVersionIfDeleted;
}

private static void SaveNewVersionIfDeleted(object sender, PageEventArgs e)
{
if (DataFactory.Instance.IsWastebasket(e.TargetLink))
{
PageData deletedPage = DataFactory.Instance.GetPage(e.PageLink).CreateWritableClone();
SaveAction action = SaveAction.ForceNewVersion;
action |= (deletedPage.PendingPublish) ? SaveAction.Save : SaveAction.Publish;
DataFactory.Instance.Save(deletedPage, action);
}
}
}
}

The code is very short and simple. In Application_Start method of the Global.asax.cs I added a new method to the DataFactory.Instance.MovedPage handler. This method checks whether the target is recycle bin and forces a new version of the page. Now if you check the version list of any of the page in the recycle bin, the latest version shows you who and when deleted the page.


Read More »