Search code examples
routesumbracoumbraco7

Umbraco routing


I am studying a project developed by some guys in Visual Studio which cooperates with Umbraco. At first, I thought that this is a .NET MVC application on top of which Umbraco sits. However, after a more thorough look I can say it has nothing to do with a .NET MVC application. There are no controllers, there is neither program.cs nor startup.cs in the solution. Instead, there are umbraco files inside umbraco and umbraco_client folders.

Of course, everything works fine. But how? When for example we write: localhost:50174/go/apply it can find the correct Umbraco content node. Who is responsible for the routing since there is no MVC routing?


Solution

  • As mentioned, the Umbraco internals by default handles the routing of an Umbraco site. The controller used to render this is the RenderMvcController here: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/Mvc/RenderMvcController.cs

    Umbraco is running inside an .NET MVC application so your assumption that it has nothing to do with MVC is actually incorrect. It is perfectly possible to register your own routes and areas just like you would have to do in any other .NET MVC application. By default - Umbraco just registers its pipeline to handle requests based on the content it manages (it is a content management system after all). When you type in a URL like /go/apply, Umbraco has a ContentFinder that locates the content corresponding to this URL path and then renders the content using the RenderMvcController (unless the route is hijacked of course).

    You can see the URL Content Finder here: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/Routing/ContentFinderByNiceUrl.cs