Class CdnImageTagHelper
- Namespace
- Cuemon.AspNetCore.Razor.TagHelpers
- Assembly
- Cuemon.AspNetCore.Razor.TagHelpers.dll
Provides an implementation targeting <img> elements that supports ICacheBusting versioning of a static image placed on a location with a CDN role. This class cannot be inherited.
[HtmlTargetElement("cdn-img")]
public sealed class CdnImageTagHelper : ImageTagHelper<CdnTagHelperOptions>, ITagHelper, ITagHelperComponent, IConfigurable<CdnTagHelperOptions>
- Inheritance
-
CdnImageTagHelper
- Implements
- Inherited Members
Examples
The following example demonstrates how to create CdnImageTagHelper with CDN-specific options.
using System;
using Cuemon.AspNetCore.Configuration;
using Cuemon.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
namespace MyApp.Examples;
public static class CdnImageTagHelperExample
{
private sealed class AssetVersion : ICacheBusting
{
public string Version => "2.1.0";
}
public static void Demonstrate()
{
var settings = new CdnTagHelperOptions
{
Scheme = ProtocolUriScheme.Https,
BaseUrl = "nblcdn.net"
};
var version = new AssetVersion();
var tagHelper = new CdnImageTagHelper(Options.Create(settings), version);
var imageUrl = settings.GetFormattedBaseUrl() + "images/logo.svg?v=" + version.Version;
Console.WriteLine(imageUrl);
Console.WriteLine(tagHelper.GetType().Name);
}
}
Constructors
CdnImageTagHelper(IOptions<CdnTagHelperOptions>, ICacheBusting)
Initializes a new instance of the CdnImageTagHelper class.
public CdnImageTagHelper(IOptions<CdnTagHelperOptions> setup, ICacheBusting cacheBusting = null)
Parameters
setupIOptions<CdnTagHelperOptions>The CdnTagHelperOptions which need to be configured.
cacheBustingICacheBustingAn optional object implementing the ICacheBusting interface.
See Also
ImageTagHelper<TOptions>