DFO 4.0.0 - 7 Customizing Asset Urls
The integration between Digizuite and Optimizely will auto-generate Optimizely URLs for the assets.
All Digizuite Assets will typically get a url like this: (host)/globalassets/(digizuite entry point)/(Asset custom url segment). The Digizuite entry point is by default "digizuite", and the custom url segment is auto generated, so an example of a path could be:
"/globalassets/digizuite/155-las-vegas.JPG".
In order to generate the url segment of the asset, the integration is calling an IMediaUrlSegmentProvider which is registered through the service configuration. By default it's configured with the following url segment provider, but it's possible to create your own, implement IMediaUrlSegment and register it as the default provider in your Initialization code.
[ServiceConfiguration(ServiceType = typeof(IMediaUrlSegmentProvider), Lifecycle = ServiceInstanceScope.Singleton)] public class MediaUrlSegmentProvider : IMediaUrlSegmentProvider { protected IUrlSegmentGenerator _segmentgenerator { get; set; } public MediaUrlSegmentProvider(IUrlSegmentGenerator SegmentGenerator) { _segmentgenerator = SegmentGenerator; } public virtual int GetAssetIdFromUrlSegment(string segment) { string idpart; if (segment.Contains('-')) idpart = segment.Split('-').First(); else if (segment.Contains('.')) idpart = segment.Split('.').First(); else idpart = segment; if (int.TryParse(idpart, out var assetid)) return assetid; else return -1;//must be new } public virtual string GetUrlSegment(EpiserverAsset asset) { var segment = _segmentgenerator.Create(asset.Name); return asset.AssetId + ((!string.IsNullOrEmpty(segment)) ? "-" + segment : "") + asset.GetExtension(); } }
Typically you would create your own if you want more control over how the url is structured for SEO reasons. Perhaps you want to include keywords in the url as well? As you can see, there are 2 methods that must be implemented - GetAssetIdFromUrlSegment and GetUrlSegment. It's essential that you can quickly retrieve the AssetId from the url as that is resolved whenever the asset is requested.
GetUrlSegment is called when the Content Asset object is created. It takes an Optimizely Asset which is essentially a dictionary with all the key/value pairs retrieved from Digizuite. By default we simply combine the AssetID and the AssetName in the url and adds the proper extension.
GetAssetIdFromUrlSegment is called whenever we have a URL Segment and quickly need to determine the AssetId.
Extending the Url
Remember, that the URL can also be extended by supporting that you can append "/" and the name of a Blob property on the url to retrieve that property. And by doing custom content asset models you can create many different blob properties and map them directly to Digizuite media formats. Read more about that here: DFO 4.0.0 - 2 Modelling Asset Content Types.