Skip to content

Instantly share code, notes, and snippets.

@pgregorynz
Created October 23, 2013 06:34
Show Gist options
  • Save pgregorynz/7113532 to your computer and use it in GitHub Desktop.
Save pgregorynz/7113532 to your computer and use it in GitHub Desktop.
Using IContentFinder to get content outside of the main content tree in Umbraco 6.1 to replicate the behavior of the pipeline in v4 that allowed you to view content outside the main content tree by its assigned URL. Based on the Gist by Lee K.
using Umbraco.Core;
using Umbraco.Web.Routing;
namespace Website.ContentHelper
{
public class ContentFinder : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentFinderResolver.Current.InsertTypeBefore<ContentFinderByNotFoundHandlers, ContentFinderCommonPages>();
base.ApplicationStarting(umbracoApplication, applicationContext);
}
}
public class ContentFinderCommonPages : IContentFinder
{
public bool TryFindContent(PublishedContentRequest contentRequest)
{
if (contentRequest != null)
{
var path = contentRequest.Uri.GetAbsolutePathDecoded();
var node = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute(path);
contentRequest.PublishedContent = node;
}
return contentRequest.PublishedContent != null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment