-
-
Save nlinker/6229429 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Umbraco.Core; | |
using Umbraco.Core.Services; | |
using Umbraco.Web.Mvc; | |
using Umbraco.Web.Routing; | |
namespace Our.Umbraco | |
{ | |
public class MyApplication : ApplicationEventHandler | |
{ | |
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) | |
{ | |
ContentFinderResolver.Current.InsertTypeBefore<ContentFinderByNotFoundHandlers, ContentFinderForWhatever>(); | |
base.ApplicationStarting(umbracoApplication, applicationContext); | |
} | |
} | |
// the example here is to have a 'virtual url'. | |
// this is required on a specific DocType, after @level=3 | |
public class ContentFinderForWhatever : IContentFinder | |
{ | |
public bool TryFindContent(PublishedContentRequest contentRequest) | |
{ | |
if (contentRequest != null) | |
{ | |
var path = contentRequest.Uri.GetAbsolutePathDecoded(); | |
var parts = path.Split(new[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries); | |
if (parts.Length > 2) | |
{ | |
var level3 = string.Concat('/', string.Join("/", parts.Take(3)), '/'); | |
var node = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute(level3); | |
if (node.DocumentTypeAlias == "Whatever") | |
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