Create your own policy and make the "access checks" in there Configure these in your Startup.cs inside ConfigureServices(IServiceCollection services) like so: services.AddAuthorization(options => You could do this using authorization policies. We also need some content based on those document types, a "Products" content node, which contains two product nodes, each with their own SKU.Authorization policy extending In this example we're going to use an empty "Products" document type to act as a list view, and "Product" document type which only contains an SKU. A common approach in a scenario like this is to have a "real" Umbraco node as a starting point. Let's create a shop controller, with an Index action showing all our products, and an Product action which will show some custom data about the product that could exists outside Umbraco. It can also be helpful to inherit from the UmbracoPageController since this includes some useful helper methods such as CurrentPage, do however note that it is not possible to inherit from RenderController when doing custom routes like this.
IPublishedContent FindContent(ActionExecutingContext actionExecutingContext) Custom route with IVirtualPageControllerĪs mentioned, with this approach we need to implement the IVirtualPageController interface, this interface only has one method FindContent which accepts an ActionExecutingContext: ForUmbracoPage() with an action for finding content on what MapControllerRoute returns, now UmbracoRouteValues will automatically be applied to any request to that controller.ĭon't fret if this all seems a bit overwhelming, we'll be going through an example of the last two options. Route a custom controller with conventional routing, using the typical call to endpoints.MapControllerRoute, and then call.Route a custom controller that implements the IVirtualPageController interface, assigning the UmbracoRouteValues to the HTTP requests will then be taken care of for you.
As you can see this is quite a lot of work, but luckily there's some much easier ways. To create an UmbracoRouteValues object generally requires: IUmbracoContextAccessor (to access the CleanedUmbracoUrl), IPublishedRouter (to create the IPublishedRequestBuilder), IPublishedRequestBuilder (to set the published content and to build the IPublishedRequest), IPublishedRequest to assign to the UmbracoRouteValues.
Do it completely manually - This requires that you have a custom route, controller, even middleware, and manually assign the UmbracoRouteValues as an HTTP request feature, however you see fit.The question is now, how do we add this request feature? There's three possibilities: Custom routes within the Umbraco pipelineįor a request to be considered executing in an Umbraco context, and therefore the Umbraco pipeline, it needs to have an HTTP request feature with the type UmbracoRouteValues, all the information required for Umbraco to handle the request is stored there.
Your custom routes to your own custom controllers will work perfectly and seamlessly alongside Umbraco's routes. Umbraco doesn't interfere with any user defined routes that you wish to have. If you're creating a package you won't have access to the Startup.cs file, so instead you must use a composer, for an example of this, see the example below. This is where to put the custom routing Public void Configure(IApplicationBuilder app, IWebHostEnvironment env)