---
title: Combining content tree-based and ASP.NET routing
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Using content tree-based routing does not exclude your projects from leveraging the [conventional routing](https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing) framework provided by ASP.NET MVC. If content tree-based routing does not match an incoming URL to any of the site's pages, it delegates the request to routes registered further down the routing table. At this point, request processing continues using the conventional routing model with the framework attempting to match the request to site-specific routes (registered in the _RouteConfig_ class). See the following diagram for illustration.

![](https://docs.kentico.com/docsassets/13/combining-content-tree-based-and-asp-net-routing/Routing_SimplifiedFlow.png)

You can take advantage of this if you wish to serve pages with content that does not need to be stored and managed in Xperience. A good example would be fully dynamic pages such as search interfaces with search results, or other pages with fully data-driven content.

## Preserving thread culture across routing modes

On [multilingual sites](https://docs.kentico.com/13/multilingual-websites/setting-up-multilingual-websites/setting-up-culture-detection.md), the culture for the handling thread is supplied by the router (based on the culture of the requested page). If you wish to invoke custom actions from the context of a page served by the router – that is, you wish to construct a URL that maps to a custom route defined for your application – you need to ensure the thread culture of the handling thread matches the culture supplied by the router. Otherwise, when clicking links handled by custom actions, users may be redirected to a different language version of the page.

For this purpose, the system provides the **CultureCodeRouteValuesKey** property. The property can be set using the **PageRoutingOptions** object when [enabling the content tree-based routing feature](https://docs.kentico.com/13/developing-websites/implementing-routing/content-tree-based-routing/enabling-content-tree-based-routing.md) (provided as an optional parameter to the **UsePageRouting**method).

```csharp

IApplicationBuilder.UsePageRouting(new PageRoutingOptions
{
    CultureCodeRouteValuesKey = "culture"
});

```

The _CultureCodeRouteValuesKey_ property:

- Sets the name of the key under which the culture code of the current router-handled page is stored in the [RouteValueDictionary](https://docs.microsoft.com/en-us/dotnet/api/system.web.routing.routevaluedictionary)  object of the request.
- Enables the framework to retrieve the current culture from route values when building URLs corresponding to your custom routes. The routes need to contain a wildcard parameter expecting a culture code and named after the key set in this property.

### Example

The following example demonstrates the usage of the _CultureCodeRouteValues_ key property on the registration of a single site-specific route.

First, set the _CultureCodeRouteValues_ property when enabling content tree-based routing:

```csharp

IApplicationBuilder.UsePageRouting(new PageRoutingOptions
{
    CultureCodeRouteValuesKey = "culture"
});

```

Then, register a route containing a wildcard parameter matching the key set in the _CultureCodeRouteValues_ property – _{culture}_ in this case.

```csharp

routes.MapRoute(
    name: "MyRoute",
    url: "{culture}/{controller}/{action}"
);

```

Now, when building URLs to the "MyRoute" route from the context of pages served by content tree-based routing (e.g., using _UrlHelper.Action("Index", "CustomController")_), the framework:

1. Matches the route "MyRoute."
2. Searches the RouteValues object for entries corresponding to the wildcards provided in the URL template. The _culture_ key is set and populated by the router when serving the source page.
3. Generates a fully qualified URL preserving the culture of the original page.
