Just Code‎ > ‎

EPiServer add events to datafactory

posted Jan 17, 2010, 1:19 PM by Peter Henell   [ updated Jan 18, 2010, 4:49 AM ]
using System;
using System.Collections.Generic;
using System.Web;
using EPiServer.Core;

namespace EPiServer
{
    
    public class PageNameRestriction : PlugIn.PlugInAttribute
    {

        public static void Start()
        {
            DataFactory.Instance.CreatingPage += new PageEventHandler(Instance_CreatingPage);
            DataFactory.Instance.DeletingPage += new PageEventHandler(Instance_DeletingPage);
            DataFactory.Instance.MovingPage += new PageEventHandler(Instance_MovingPage);
        }

        static void Instance_MovingPage(object sender, PageEventArgs e)
        {
            if (e.TargetLink == PageReference.WasteBasket)
            {
                e.CancelReason = "Inga sidor får tas bort";
                e.CancelAction = true;
            }
        }

        static void Instance_DeletingPage(object sender, PageEventArgs e)
        {
            e.CancelAction = true;
            e.CancelReason = "Inga sidor får tas bort";
        }

        static void Instance_CreatingPage(object sender, PageEventArgs e)
        {
            if (e.Page.PageName.StartsWith("CMS"))
            {
                e.CancelAction = true;
                e.CancelReason = "Namnstandarden förbjuder detta namn";
            }
        }
    }
}
Comments