Skip to content

Instantly share code, notes, and snippets.

@Vrijdagonline
Forked from pgregorynz/IContentFinder example
Last active August 29, 2015 14:14
Show Gist options
  • Save Vrijdagonline/50c4029f86e67394c8f4 to your computer and use it in GitHub Desktop.
Save Vrijdagonline/50c4029f86e67394c8f4 to your computer and use it in GitHub Desktop.
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