Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Created December 2, 2013 22:40
Show Gist options
  • Save warrenbuckley/7760400 to your computer and use it in GitHub Desktop.
Save warrenbuckley/7760400 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using umbraco.cms.businesslogic.member;
using Umbraco.Core;
using Umbraco.Web.Routing;
namespace MyExampleSite.BusinessLogic
{
public class MemberProfileContentFinder : IContentFinder
{
public bool TryFindContent(PublishedContentRequest contentRequest)
{
var urlParts = contentRequest.Uri.GetAbsolutePathDecoded().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
//Check if the Url Parts
// Starts with /member/*
if (urlParts.Length > 1 && urlParts[0].ToLower() == "member")
{
//Lets try & find the member
var memberName = urlParts[1];
//Try and find a member where the property matches the memberName
var tryFindMember = Member.GetAll.SingleOrDefault(x => x.getProperty("profileURL").Value.ToString() == memberName);
//See if tryFindMember is not null
if (tryFindMember != null)
{
//Need to set the member ID or pass member object to published content
//Set the Published Content Node to be the /Profile node - can get properties off it & my member profile in the view
contentRequest.PublishedContent = contentRequest.RoutingContext.UmbracoContext.ContentCache.GetByRoute("/profile");
}
else
{
//Need to throw some custom: Not found Member
//as opposed to filitering down to other iContentFinders and show the 404
}
//Return true to say found something & stop pipleine & other contentFinder's from running
return true;
}
//Not found any content node to display/match - so run next ContentFinder in Pipeline
return false;
}
}
}
@zpqrtbnk
Copy link

zpqrtbnk commented Dec 3, 2013

How to pass that found member to the pipeline: we don't have a recommended solution at the moment. See http://issues.umbraco.org/issue/U4-61, one suggestion was to implement UmbracoContext.Items so you could do UmbracoContext.Items["myMember"] = member. But we're not there yet.
In the meantime... HttpContext.Current.Items["myMember"] = member. Bit ugly, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment