Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Add Comment
Please, Sign In to add comment