Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Web.Configuration;
using Umbraco.Core;
using Umbraco.Web.Routing;
namespace Moriyama.Core.Routing.ContentFinders
{
public class UmbracoHiddenFolderContentFinder : ContentFinderByNiceUrl
{
public override bool TryFindContent(PublishedContentRequest contentRequest)
{
var umbracoHiddenFolderAlias = WebConfigurationManager.AppSettings["UmbracoHiddenFolderAlias"] ?? "umbracoHiddenFolder";
// We call the base content finder here which is ContentFinderByNiceUrl,
// that is why we remove ContentFinderByNiceUrl from the collection of content finders
if (base.TryFindContent(contentRequest))
{
// We see if we can find a node and if it is not a Hidden Folder then we return true
// We don't want to return a match for a folder by the normal nice URL
if (contentRequest.PublishedContent != null)
{
return contentRequest.PublishedContent.ContentType.Alias != umbracoHiddenFolderAlias;
}
}
// Here we have to prepare the route
var path = contentRequest.Uri.GetAbsolutePathDecoded();
string relativeRoute;
string route;
// if a domain has been set (multiple brands in one Umbraco - then routes have the id of that domain prepended to the path)
if (contentRequest.HasDomain)
{
relativeRoute = DomainHelper.PathRelativeToDomain(contentRequest.DomainUri, path);
route = contentRequest.UmbracoDomain.RootContentId + "/" + relativeRoute.Replace("/_folder-", "/");
}
else
{
relativeRoute = path;
route = relativeRoute.Replace("/_folder-", "/");
}
// Now we can try to find the folder after removing the _folder- prefix
var node = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute(contentRequest.RoutingContext.UmbracoContext.InPreviewMode, route);
if (node != null && node.ContentType.Alias == umbracoHiddenFolderAlias)
{
contentRequest.PublishedContent = node;
return true;
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.