When you make a page request to the MVC application, a controller is responsible for returning the response to that request. The controller can perform one or more actions. The controller action can return different types of action results based on the request.
Default Controller Action
By default, Umbraco will execute every request via it's built-in default controller: Umbraco.Cms.Web.Common.Controllers.RenderController. Umbraco site automatically routes all the front-end requests via the Index action of the RenderController.
It is possible to implement a custom Controller to replace the default implementation to give complete control during the Umbraco request pipeline execution. You can configure Umbraco to use your implementation in a class with a composer. For example:
MyRenderController.cs
usingMicrosoft.AspNetCore.Mvc.ViewEngines;usingMicrosoft.AspNetCore.Mvc;usingUmbraco.Cms.Core.Composing;usingUmbraco.Cms.Core.Web;usingUmbraco.Cms.Web.Common.Controllers;usingUmbraco.Cms.Web.Website.Controllers;namespaceYourProjectNamespace;publicclassMyRenderController:RenderController{publicMyRenderController(ILogger<MyRenderController> logger,ICompositeViewEngine compositeViewEngine,IUmbracoContextAccessor umbracoContextAccessor): base(logger, compositeViewEngine, umbracoContextAccessor) { }publicoverrideIActionResultIndex() =>Ok("MyRenderController Index method hit with CurrentPage.Name set to: "+CurrentPage?.Name);}publicclassMyComposer:IComposer{publicvoidCompose(IUmbracoBuilder builder) {builder.Services.Configure<UmbracoRenderingDefaultsOptions>(renderOptions =>renderOptions.DefaultControllerType=typeof(MyRenderController)); }}
Ensure that the controller inherits from the base controller Umbraco.Cms.Web.Common.Controllers.RenderController. You can override the Index method to perform any customizations of your choice.
Custom Controller Selection
You can create Custom controllers for different Document Types and Templates. This is termed 'Hijacking Umbraco Routes'. For details on how this process works, see the Custom MVC Controllers (Umbraco Route Hijacking) article.