Copied to clipboard

Flag this post as spam?

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


  • person2 11 posts 81 karma points
    Jul 03, 2020 @ 07:02
    person2
    0

    Route hijacking problem mapping template to custom controller

    I have a controller here called 'ReverseProxyController'

     public class ReverseProxyController : Umbraco.Web.Mvc.RenderMvcController
    {
        public ActionResult ReverseProxy.....
    

    I have also created a Document Type called 'Reverse Proxy'

    But when I create a Template called 'Reverse Proxy' it maps straight to Views/ReverseProxy instead of getting hijacked and going to the ReverseProxyController enter image description here

    Not sure what I am missing, I went through the documentation and read the following forum post but I still can't get it to work. https://our.umbraco.com/documentation/reference/routing/custom-controllers

    https://our.umbraco.com/forum/using-umbraco-and-getting-started/84844-route-hijacking-with-custom-controller

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 03, 2020 @ 16:00
    Marc Goodson
    0

    Hi Person2

    What is the Url that you are requesting?

    Eg do you have a content item created using the ReverseProxy Document Type?

    If you can request the Url of that page, whilst debugging and setup an additional 'Index' route in your controller, you can set some breakpoints and see if it's hitting the controller first at all...

    eg

      public override ActionResult Index(RenderModel model)
        {
            //set a breakpoint here
            return CurrentTemplate(model);
        }
    

    When a request comes into Umbraco it tries to find content matching that Url, looks up it's document type, uses the alias of the document type to see if a controller has been created in the format docTypeAliasController, then looks to see which template the page has been published with, looks for an action on the controller matching that alias, then fallback to use the Index action...

    I'm assuming too that your ReverseProxy ActionResult accepts a 'RenderModel' object

      public ActionResult ReverseProxy(RenderModel model)
        {
    

    ??

    Anyway be interesting to see how far you are getting in the process!

    regards

    Marc

  • person2 11 posts 81 karma points
    Jul 07, 2020 @ 10:29
    person2
    0

    Maybe I misunderstood the documentation. But I have it working now.

    If I create a Document Type with the controller name then it will automatically create a Template as well, which works how I want.

    But I was trying to manually add a Template after the Document Type and I think that was overriding.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 07, 2020 @ 10:41
    Marc Goodson
    0

    Hi person2

    Good you got it working, yes, that's generally the convention to follow, you can add an alternative template to the doc type, and create an alternative action result matching the template name, but you also have to request the page 'WITH' that alt template - using ?altTemplate= to get the request routed to the alternative action, but usually you don't need to do this as you've found!

    regards

    marc

  • person2 11 posts 81 karma points
    Jul 07, 2020 @ 11:26
    person2
    0

    Thanks Marc

Please Sign in or register to post replies

Write your reply to:

Draft