Try our conversational search powered by Generative AI!

Loading...
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Asset URL resolver

This topic describes how to display assets for catalog content using the AssetUrlResolver and the AssetContainer interface. The functionality is demonstrated in the Episerver Commerce sample site on the Assets tab for catalog content, where users can define a set of assets to display.

How it works

EntryContentBase and NodeContent implements IAssetContainer, which contains the property CommerceMediaCollection. Content that implements the interface IAssetContainer can contain several assets.

In many cases, you can define several asset items for a catalog item, but only one is shown on the site. By default, the first item is used in the asset collection in the catalog UI, ordered by the SortOrder property. You can change this behavior for content types. By adding a type to the AssetUrlConventions class, you can set a default group for the specific content type. Assets in this group are always more important than assets in other groups, regardless of sort order.

GetAssetUrl

The GetAssetUrl method gets the default asset for content. The collection of assets is ordered by SortOrder. The first item in the list is selected, which is in the specified default group for the content. If there is no default group, or there is no asset for the default group, the first item in the list is used.

AssetUrlConventions

The AssetUrlConventions  class can specify a default asset for a content type. The generic AddDefaultGroup(string groupName) method adds the specified group name as the default group for the generic type, which has to implement IAssetContainer.

You can have only one default group name for each specific content type. An InvalidOperationException is thrown if there are several default groups defined to be set for the same content type.

GetDefaultGroup

GetDefaultGroup gets the default group for the content. This method checks for the exact type, if there is a default group on that level. If there is no registered default group specified on the exact type, the method checks the base class for any default group registered on that type. The method recursively checks for a registered type until it is found, or until the base type no longer implements IAssetContainer.

Related topic

Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 12, 2015

Recommended reading