Copied to clipboard

Flag this post as spam?

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


  • Peter Sinke 11 posts 82 karma points
    Apr 09, 2019 @ 14:31
    Peter Sinke
    0

    Continue with ContentFinder after Custom route failed?

    I've got some products that I have created a custom route and a controller for. When the URL matches /something/{id}/{name} the route is picked up by the controller. This is fine, but the website is a complete rebuild from an older site. The URL structure is the same for the products, but the IDs have changed. So what can happen is that an old URL can be called, and the custom route picks this up, but cannot find the right product. For these kinds of scenarios I usually have a property on a doctype called 'Old URLs' which is a textarea where each line can hold an old URL. To redirect the user to the correct URL, I use a custom ContentFinder.

    What I would like to do is have Umbraco continue with the ContentFinder after it cannot successfully get the correct product in the controller.

    Is there any way to do this? Just creating a 404 response header from the controller doesn't seem to do it.

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 09, 2019 @ 18:25
    Corné Strijkert
    0

    Hi Peter,

    What I know about content finders is that content finders are part of the Umbraco request pipeline, in other words, mixing content finders and custom mvc routes is not possible.

    Creating a 404 response from you controller will indeed give you just the 404 result. It's the latest HTTP response that will be send to the browser.

    For old URL's that doesn't match with URL's on the new site I usually create entries in the rewriteMaps.config file.

    When old URL's accidentally hits your controller method and you know where to redirect to, mabye you can return a 301 redirect or something like that?

  • Peter Sinke 11 posts 82 karma points
    Apr 09, 2019 @ 18:47
    Peter Sinke
    0

    Hi Corné,

    Thanks for your reply. I was afraid of that. I was just hoping there was some way to throw the thread back into the Umbraco pipeline :) I guess I'll place the ContentFinder logic in a more accessible location so the controller can search for an old URL when the route fails. There are too many products to manually create a rewrite file.

    Grts,

    Peter

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 09, 2019 @ 19:26
    Corné Strijkert
    0

    There are many approaches to achieve the same :) Each with its own pros and cons.

    When no product was found on your custom route, you can redirect to another Controller that is responsible for finding and redirecting to alternate (old) URLs (or catch all redirect).

    I guess the same logic is usable for the ContentFinder implementation.

Please Sign in or register to post replies

Write your reply to:

Draft