using System; using Composite.Data; using Composite.Data.Types; using Composite.Core.Logging; using Composite.Core.WebClient.Renderings; using Composite.Core.WebClient.Renderings.Plugins.RenderingResponseHandler; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; namespace RenderingResponseHandlerSample { [ConfigurationElementType(typeof(NonConfigurableRenderingResponseHandler))] public class RenderingResponseHandlerPluginSample : IDataRenderingResponseHandler { // Have the TCP logger running to see the string being logged - see Composite.Tools.TcpCustomTraceListener // This sample will redirect requests for pages and media containing the word 'secret' in their title / path. public RenderingResponseHandlerResult GetDataResponseHandling(DataEntityToken requestedItemEntityToken) { IData requestedData = requestedItemEntityToken.Data; bool redirect = false; if (requestedData is IPage) { IPage requestedPage = (IPage)requestedData; LoggingService.LogVerbose("Sample", string.Format("Request for page '{0}'.", requestedPage.Title)); if (requestedPage.Title.ToLower().Contains("secret")) { redirect = true; } } else if (requestedData is IMediaFile) { IMediaFile requestedMediaFile = (IMediaFile)requestedData; LoggingService.LogVerbose("Sample", string.Format("Request for media file '{0}'.", requestedMediaFile.CompositePath)); if (requestedMediaFile.CompositePath.ToLower().Contains("secret")) { redirect = true; } } if (redirect) { return new RenderingResponseHandlerResult { PreventPublicCaching = true, RedirectRequesterTo = new Uri("http://docs.composite.net/") }; } else { return new RenderingResponseHandlerResult { PreventPublicCaching = false }; } } } }