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 »

Related Posts:


6 Responses to How to determine who deleted the page in EPiServer

  1. Damian
    June 18, 2010 at 1:29 PM
    Hi Maras
    Very nice, and like always useful, but like I have said you before, implementing you own custom HttpModule is in my opinion a better place place to put functionality like that.

    Damian ;)
  2. Adam
    June 18, 2010 at 4:11 PM
    Damian,

    I have to respectfully disagree, why would you use HttpModuel for something that intrinsicly is a prt of an EPiServer workflow.

    Why would you want to have something fired on every request when you can only have it run on that specific occasion?
  3. Dominik
    June 18, 2010 at 7:55 PM
    Nice, I always wanted to have this but never have time to write it (I know - lame excuse ;) ).
  4. Joel Abrahamsson
    June 19, 2010 at 12:15 AM
    Good stuff!

    Regarding the discussion about a HTTP module or not, I would say that the cleanest and most reusable (in terms of ease of use) way would be to use the new and great concept introduced in CMS of an InitializableModule (more info: http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-6/EPiServer-CMS-60/Initialization/#Creating)
  5. Marek Musielak
    June 19, 2010 at 8:58 PM
    Right, I've heard about the InitializableModule. Unfortunately I haven't had a chance to work for a longer with EPiServer 6 yet. However, now it's on the top of my todo list ;)
  6. Damian
    June 21, 2010 at 11:28 AM
    Adam,

    First of all for me it doesn't matter if this is a part of EPiServer or not, Global.asax is neither. I'm just saying that single responsibility principle and as Joel wrote (thank you, and great talks during Summit, by the way) reusable reasons lead me to use the HttpModule.

    Second - Modules are created per working thread (as far as I know), and this is up to you which event you choose to attach to. Therefore it doesn't have to be a BeginRequest one, it can be the Moved page or whatever you are interested in. One thing which we have to keep in mind is to unbind it when ASP.NET engine removes the module.

    Damian

Post a Comment