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.
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();
}
}
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();
}
}
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.
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.
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
I think you need to use composition now.
https://our.umbraco.com/forum/umbraco-8/96167-registering-custom-routes-in-umbraco-8#comment-304611
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 {
}
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!
Hi, Simple custom controller solution:
code
}
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.