In this tutorial, you will learn how to correctly register custom URLs within the routing table within Umbraco 8. Custom routing will allow you to do things like use vanilla MVC controllers in Umbraco. Pre Umbraco V8 the standard way of configuring route handling was normally done from within the global.ascx. First, you would register a custom route handler. This was done by creating a RouteConfig.cs file within App_Start. Within RouteConfig.cs a list of custom routes would be defined that would instruct the routing engine how to map a URL to a controller and an action. As of Umbraco V8, registering stuff within the global.ascx is no longer the recommended approach.

In Umbraco V8 the concept of components and composers were introduced. Components are now the recommended way of hooking into the Umbraco request pipeline to run some custom code, like adding custom routes. The focus of this article is creating a routing component. It is not an introduction to components. An introduction to this subject can be found here. If you need to register an MVC controller, or you need to do something non-standard with your routes, then read on.

Registering A Component

Registering and creating a new component within Umbraco is very easy. First, you will need to create a composer to register the component, the code to do this looks like this:

The next task will be to create a component to handle the routing:

In this example, we are registering a route to access standard MVC controller:

RegisterCustomRouteComponent will now work in exactly the same manner as the older RouteConfig.cs file would have worked. Happy coding!