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
    22 days ago
    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 154 posts 243 karma points
    22 days ago
    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 95 posts 127 karma points
    5 days ago
    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 95 posts 127 karma points
    5 days ago
  • Marc Goodson 781 posts 5137 karma points MVP 3x c-trib
    5 days ago
    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();
        }
    }
    

    }

Please Sign in or register to post replies

Write your reply to:

Draft