Don't miss out Virtual Happy Hour this Friday (April 26).

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 document briefly describes how the display of assets for catalog content can be implemented 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 be displayed.

How it works

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

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

GetAssetUrl

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

AssetUrlConventions

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

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

GetDefaultGroup

GetDefaultGroup will get the default group for the content. This method will start to look at 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 will look at the base class to see if there is any default group registered on that type. The method will recursively look for a registered type until it is found, or until the base type does not implement IAssetContainer anymore.

See also

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

Last updated: Dec 08, 2014

Recommended reading