Override the page strategies

Use this procedure to create a custom frontend strategy that will compile only specific frontend pages, instead of all the pages of the site, which is the default behavior. You do this by implementing the IPageKeyStrategy interface, then register it in Sitefinity's object factory during the Boostrapper.Bootstrapped event.

In the custom strategy, the method GetPageIds returns the IDs of the pages that will be precompiled. The following code is an example of a custom frontend strategy implementation:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Web.Compilation;

namespace SitefinityWebApp
{
   class CustomFrontendPageKeyStrategy : IPageKeyStrategy
   {
       public IList<Guid> GetPageIds()
       {
           var siteRootId = Guid.Parse("1C6F7683-70C4-4A79-8443-78358FEEA91A");
           var manager = PageManager.GetManager();
           var ids = manager.GetPageNodes()
             .Where(x => x.RootNodeId == siteRootId)
             .Where(x => x.NodeType == NodeType.Standard)
             .OrderBy(x => x.RootNodeId)
             .Select(x => x.Id).ToList();
           return ids;
       }
   }
}

The following code shows how to register the custom strategy:

C#
using System;
using Telerik.Microsoft.Practices.Unity;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Web.Compilation;

namespace SitefinityWebApp
{
   public class Global : System.Web.HttpApplication
   {
       protected void Application_Start(object sender, EventArgs e)
       {
           Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
       }

       private void Bootstrapper_Bootstrapped(object sender, System.EventArgs e)
       {
           ObjectFactory.Container.RegisterType<IPageKeyStrategy, CustomFrontendPageKeyStrategy>("Frontend");
       }
   }
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
New to Sitefinity?