Hide menu Last updated: May 15 2017
Area: Episerver Commerce Applies to versions: 10 and higher
Other versions:

Routing

This topic explains the routing concept used for displaying catalog content in Episerver Commerce.

How it works

The Commerce routing system extends the Episerver CMS Routing system to expose catalog content like products, variants, and categories using individual URLs. The data sent to the client browser is compiled by a matching rendering template. Categories have their own URL and can have their own rendering template, for instance to display a product listing. See Commerce rendering templates for more information.

Catalog content URLs have two forms:

  • Hierarchical URL. In the form domain/language/catalog/category/product, following the catalog's structure. For example, mysite.com/en/wine/accessories/corkscrew.
  • Simple address/SEO URL. A single segment uniquely identifying content and its language. For example, mysite.com/professional-corkscrew-en.aspx.

The SEO URL field has been part of the catalog information since previous versions of Episerver Commerce. But with the new routing, it works the same as the Episerver CMS "Simple address" concept. Hence, you may see both terms used.

Registering routes

To enable routing to catalog content, register the catalog partial router in an EPiServer.Framework.IInitializableModule using the CatalogRouteHelper.

Outgoing routes

Outgoing routes are used when rendering links in the template. For example, using the Html.ContentLink helper (ASP.NET MVC), the EPiServer.Web.Routing.UrlResolver class or links are added to an Xhtml property by an editor. Commerce routes also register an outgoing route, which is determined by the flag passed to CatalogRouteHelper in the initialization:

  • CatalogRouteHelper.MapDefaultHierarchialRouter(routes, false) uses hierarchical links.
  • CatalogRouteHelper.MapDefaultHierarchialRouter(routes, true) uses the SEO URL in links.

Working with hierarchical URLs

Hierarchical URLs are constructed using the Name in URL property of each content instance in the hierarchy, leading to the requested content. The first segment is the catalog, followed by categories and subcategories down to the target category, product, variant, and so on. To determine the language, either a language segment (for example, "en/") is prepended, or the configured site host mapping is used (see Globalization scenarios for more information).

The Name in URL property value is automatically generated from the Name when new content is created. Because only certain characters are valid in a URL and because the Name in URL needs to be unique in the catalog, it may not match Name. A unique value is added to the end of the Name in URL if other content in the catalog has the same Name in URL as the new content Name. You can edit Name in URL to any valid value - it does not have to resemble Name.

Note: If your site uses Episerver CMS version 10.6 or higher, your developer can define a custom character set to be used with the Name in URL and the SEO URL fields. The custom set can support characters outside RFC 1738. For more information, see Internationalized Resource Identifiers (IRIs) and URL segment and SEO URI.

Working with SEO URLs

SEO URLs are stored in the SEO URL property and should be unique across all catalogs and languages, which is why only one segment is needed to identify the requested content. It also means that the URL is unaffected by moving the product in the catalog tree, or changing the Name in address of a content somewhere above in the hierarchy.

The SEO URL property value is automatically generated from the Name when content is created. For additional language versions, the language code is appended to make the SEO URL unique. Because only certain characters are valid in a URL and because the SEO URL needs to be unique across catalogs, it may not match the Name. By default, an .aspx extension is used, but the SEO URL can be edited to any valid value. It does not have to resemble Name or include an extension.

Changing the default generation of SEO URL, and name in url

The class UniqueSeoGenerator is called when an SEO URL or uri segment (name in url) is created. To override this logic, inherit from UniqueSeoGenerator and override GenerateSeoUri and/or GenerateUriSegment. The custom unique SEO generator must be registered in an initialization module.

Related topics

Comments