Copied to clipboard

Flag this post as spam?

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


  • Zac 239 posts 541 karma points
    Apr 02, 2015 @ 17:15
    Zac
    0

    Advanced route hijacking on similar document type names

    How can we extend the route hijacking to add routes for similar document type names.

    For example, if we have the following document types

    • NewsList1
    • NewsList2
    • NewsList3

    we would like all of them to route to the controller NewsListController (which extends RenderMvcController or a custom implementation of it).

    Is there a way to route these document types to the controller without creating separate controllers for each unique doc type alias?  We have similar doc types created multiple times to allow for minor UI differences, but the base functionality is the same.

    Can we add our own custom routes to Umbraco's hijacked routing table?  If so, how would this be accomplished?

    Any advice or direction would be helpful.

     

  • Zac 239 posts 541 karma points
    Apr 03, 2015 @ 03:07
    Zac
    0

    bump

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 03, 2015 @ 12:00
    Dave Woestenborghs
    0

    You can set a defaultcontroller for route hijacking.

    So all doctypes will use that controller. You still can have controllers for specific doctypes.

    https://our.umbraco.org/documentation/Reference/Templating/Mvc/custom-controllers#Changethedefaultcontroller

    Dave

  • Zac 239 posts 541 karma points
    Apr 03, 2015 @ 16:40
    Zac
    0

    Yes, we're aware of that and are using that for other functionality, but we were hoping there'd be a way to add our own custom routes to the hijacked routing table.

    Do you know if that's possible?  We'd like to 1) query the doc types on app start, 2) find the "similar doc types" then 3) register them as hijacked routes.

    1 and 2 are very easy but we can't figure out how to do 3.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Apr 03, 2015 @ 16:51
    Dave Woestenborghs
    0

    I think the easiest way to do this would be

    To create controllers for each of your doctypes and inherit them from one base controller

    Dave

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 03, 2015 @ 17:35
    Nicholas Westby
    1

    There may be a better way (e.g., overload however Umbraco is finding the controller by doctype), but you should be able to at least create your own route using a catch-all expression and a custom route constraint that matches the doctype based on a regular expression. If you want to look for a more elegant way, here is some Umbraco source code you'll want to look into:

  • Zac 239 posts 541 karma points
    Apr 09, 2015 @ 17:02
    Zac
    0

    Thanks a lot Nicholas.  

    This is more what we were looking for.  We'll give it a shot and post our results back here.

Please Sign in or register to post replies

Write your reply to:

Draft