Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Sep 12, 2017 @ 06:42
    John C Scott
    0

    Hijack Routing a Specific Template

    I'm using "Route Hijacking" for a specific document type and that is good. However I wanted multiple document types that are using the same template to also execute the same controller.

    I see from the documentation that I have the options to define a controller action for a specific template for a specific document type. Is there a way to attach a controller to a specified template for any document type?

    I see I can have a controller for any document type and any template as the final third action. But is there any way that it is possible to route any of the document types that already have controllers to their defined controller if one exists after being intercepted by my "catch all" one?

  • Kevin Jump 2310 posts 14694 karma points MVP 7x c-trib
    Sep 12, 2017 @ 06:54
    Kevin Jump
    101

    HI

    if you are replacing the default Controller for all doctypes and templates using

    DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(MySuperGlobalController));
    

    then your replacement controller should inherit from umbraco's RenderMvcController class.

    public class MySuperGlobalController : Umbraco.Web.Mvc.RenderMvcController
    

    if you do this, then calling base.Index(Model) from within your Index method will fall through to the controller finding logic in Umbraco and any other controllers (such as your doctype specific ones) will be fired too after your catch all one has ran.

    so something like this ?

    public class MySuperGlobalController : Umbraco.Web.Mvc.RenderMvcController 
    {
        public override ActionResult Index(RenderModel model)
        {
          // do the global stuff you need to here.
            return base.Index(model);
        }
    }
    
  • John C Scott 473 posts 1183 karma points
    Sep 12, 2017 @ 14:43
    John C Scott
    0

    Thanks Kevin - that's very clear thank you :)

Please Sign in or register to post replies

Write your reply to:

Draft