Copied to clipboard

Flag this post as spam?

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


  • Thomas Heaney 8 posts 29 karma points
    Feb 28, 2019 @ 16:12
    Thomas Heaney
    0

    Adding custom MVC routes in v8

    Does anyone know how to add custom MVC routes in v8? With v7 I used an ApplicationEventHandler class but this is not available.

    I did make an attempt with Composers and Components but it didn't go very well.

  • Carlos Mosqueda 177 posts 267 karma points
    Feb 28, 2019 @ 16:19
    Carlos Mosqueda
    0

    It looks like so far the documentation has not been update, as you probably saw.

    But if you want to do some digging, in the Umbraco.Web folder, there is a Routing folder and in the main Umbraco.web there is a RouteCollectionExtensions class.

  • seanrock 140 posts 307 karma points
    Mar 17, 2019 @ 10:58
    seanrock
    0

    if you check the github docs repo, there is mention about compositions and that ApplicationEventHandler is gone.

    https://github.com/umbraco/UmbracoDocs/blob/master/Tutorials/Porting-Packages-V8/index.md

  • seanrock 140 posts 307 karma points
    Mar 17, 2019 @ 14:41
  • Marc Goodson 1190 posts 8011 karma points MVP 5x c-trib
    Mar 17, 2019 @ 23:20
    Marc Goodson
    0

    Hi Thomas

    Have knocked up an example here:

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; using Umbraco.Core.Composing; using Umbraco.Web; using Umbraco.Web.Mvc;

    namespace Umbraco8.Components {

    public class RegisterCustomRouteComposer : ComponentComposer<RegisterCustomRouteComponent>
    {
    
    }
    
    public class RegisterCustomRouteComponent : IComponent
    {
        public void Initialize()
        {
            RouteTable.Routes.MapUmbracoRoute("Product Details", "product/details/{id}", new
            {
                controller = "SuperProduct",
                action = "Details",
                id = UrlParameter.Optional
            }, new UmbracoVirtualNodeByIdRouteHandler(1105));
        }
    
        public void Terminate()
        {
            throw new NotImplementedException();
        }
    }
    

    }

  • Hugo Becerra 12 posts 82 karma points
    Sep 11, 2019 @ 11:35
    Hugo Becerra
    0

    Hi guys,

    any of you have a solution for this?

    We are having this problem right now --> https://our.umbraco.com/forum/umbraco-8//99009-umbraco-v8-custom-routing-for-umbracoapicontroller

    Thanks!

  • Jevgenijus Zaboras 1 post 71 karma points
    Jan 09, 2020 @ 13:32
    Jevgenijus Zaboras
    0

    Hi, Simple custom controller solution:

    enter image description here code

     using System.Web.Mvc;
     using Umbraco.Web.Mvc;
    
    namespace UmbracoDemo.Controllers
    {
        public class HomeController : UmbracoController
        {
            // GET: Home
            public ActionResult Index()
            {
                return View();
            }
        }
    }
    

    code

    using System;
    using System.Web.Mvc;
    using System.Web.Routing;
    using Umbraco.Core;
    using Umbraco.Core.Composing;
    using UmbracoDemo.Controllers;
    namespace UmbracoDemo {
        public class RegisterCustomRouteComposer : IUserComposer
        {
            public void Compose(Composition composition)
            {
                 composition.Register<HomeController>(Lifetime.Request);
                 composition.Components()
                 .Append<RegisterCustomRouteComponent>();
            }
    }
    public class RegisterCustomRouteComponent : IComponent
    {
        public void Initialize()
        {
            RouteTable.Routes.MapRoute(
                "HomePage",
                "home/index",
                new { controller = "Home", action = "Index" }
                );
        }
    
        public void Terminate()
        {
            throw new NotImplementedException();
        }
    }
    

    }

Please Sign in or register to post replies

Write your reply to:

Draft