Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Simon 692 posts 1068 karma points
    Jul 22, 2016 @ 20:27
    Simon
    0

    Difference between Custom Routes and Content Finder

    Hi Guys,

    I would like to know exactly what is the difference between Custom Routes and Content Finder, as if what the circumstances when to use one and not the other, please?

    Thank you for your feedback

    Kind Regards

  • Marc Goodson 2126 posts 14218 karma points MVP 8x c-trib
    Jul 23, 2016 @ 00:41
    Marc Goodson
    6

    Hi Simon

    A Custom Route

    https://our.umbraco.org/documentation/reference/routing/custom-routes

    is a mapping of a specific route, eg /products/{actionName}/{id} to a particular MVC controller.

    This is useful if you have content outside of Umbraco, perhaps a Product repository in a custom database table that you want to merge with content from Umbraco, or maybe if you just want to run some custom controller logic before return Umbraco content. (There is also the technique of Route Hijacking if your controller logic is relevant for a particular document type: https://our.umbraco.org/documentation/reference/routing/custom-controllers) or integrate an existing MVC application alongside Umbraco.

    ContentFinder

    A ContentFinder is part of the Umbraco request pipeline. When a request comes into Umbraco a series of ContentFinders (registered as ContentFinderResolvers) are executed one after another until an appropriate content node is found. If none are found matching the request a LastChanceFinder is executed that returns a 404.

    You can create your own finders by implementing IContentFinder in a class, and adding it to the list of ContentFinderResolvers (or setting it as the LastChanceFinder if you want custom logic if how the 404 is returned)

    https://our.umbraco.org/documentation/reference/routing/request-pipeline/icontentfinder

    So with this technique, you could have custom code run on any 'url' request, you do not have to map a route for it.

    Summary

    There is overlap in the two techniques but with a ContentFinder you are essentially just finding and returning an Umbraco node by implementing a Custom rule to find it; and with a custom route, you are saying I know the Url format of the request I want to handle, and I want this request to run via my custom controller so I can manipulate the IPublishedContent model before sending it to a template.

    Exampl-ish

    So if you had the notion of a set of products in your website, and they had a special identifying product id eg SKU-234-222

    A custom IContentFinder could be written so that any request ending in the format /SKU-- could return your Umbraco product node that had a matching SKU in it's ProductSku property field.

    Whereas a custom route could be setup for /products/{sku} that looked up the SKU in an external database 'SKU-234-222' and then using the information from the database return a 'virtual' IPublishedContent node to an Umbraco template 'as if' the product had been created as a node in Umbraco...

    if that makes sense ?

    regards

    Marc

  • Simon 692 posts 1068 karma points
    Jul 23, 2016 @ 04:44
    Simon
    0

    Hi Marc,

    Thank you for finding time to answer my question. It was helpful.

    So, for example, for friendly SEO Urls, (in my case I have a dilemma what to use for a search functionality), where I have real-estate properties, linked with localities and property types, in Umbraco as nodes.

    And for example, I was the following SEO friendly URL:

    mysite.com/properties/locality/villa/property-name-id

    Which one should I user, customer routes or content finder?

    Thank you once again in advance.

    Kind Regards

  • Marc Goodson 2126 posts 14218 karma points MVP 8x c-trib
    Jul 23, 2016 @ 09:04
    Marc Goodson
    3

    Hi Simon

    It's hard to know without the site in front of me (I'm all instinct now) but...

    In this instance I would probably create a PropertyList doc type, a Locality DocType, a PropertyType DocType and a RealEstate DocType.

    Enabling you to create the RealEstate nodes in Umbraco in a structure that matched the url you want them to be requested on.

    (but there maybe something I don't know about the instance of what you are trying to create, eg how the RealEstate items are imported into Umbraco)

    This would fall down if a RealEstate can be of more then one property type ? or locality ?

    Additionally there is a special hidden feature of Umbraco, called 'UmbracoUrlAlias'

    https://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracourlalias/

    essentially if you add a property called umbracoUrlAlias to your RealEstate document type, you can specify a list of alternative urls that the page should be returned under.

    But if the above wasn't possible for some reason, I would probably implement an IContentFinder in this scenario, ie if you have the RealEstate items created in one ListView, and there are dropdowns for 'PropertyType' and 'Locality', just because it's simple, and you just want to find and return Umbraco Content.

    With the proviso that if I needed to or strongly felt that in the future I might need to pull in extra information about the RealEstate item (stored outside of Umbraco eg. Real Estate availability status from some kind of 3rd party), then I'd probably use a controller and a custom route.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft