InlineTagHelper Class

Base class for TagHelpers that inline external files into HTML elements with caching support.

public abstract class InlineTagHelper : TagHelper

Remarks

This abstract class provides functionality to read files from the web root, cache their contents, and automatically invalidate the cache when files change. It supports reading files as both text and Base64-encoded strings.

Inheritance
TagHelper InlineTagHelper

Constructors

NameDescription
InlineTagHelper(IWebHostEnvironment, IMemoryCache, ILogger)Initializes a new instance of the InlineTagHelper class.

InlineTagHelper(IWebHostEnvironment, IMemoryCache, ILogger)

InlineTagHelper.cs

Initializes a new instance of the InlineTagHelper class.

protected InlineTagHelper(IWebHostEnvironment webHostEnvironment, IMemoryCache cache, ILogger logger)

Parameters

webHostEnvironment IWebHostEnvironment
The web host environment for accessing web root files.
cache IMemoryCache
The memory cache for storing file contents.
logger ILogger
The logger used to report missing files.

Methods

NameDescription
GetFileContentAsync(string?)Gets the file content as a string with caching support.
GetFileContentBase64Async(string?)Gets the file content as a Base64-encoded string with caching support.

GetFileContentAsync(string?)

InlineTagHelper.cs

Gets the file content as a string with caching support.

protected Task<string?> GetFileContentAsync(string? path)

Parameters

path string?
The relative path to the file in the web root.

Returns

Task<string?> The file content as a string, or null if the path is null or the file doesn't exist.

GetFileContentBase64Async(string?)

InlineTagHelper.cs

Gets the file content as a Base64-encoded string with caching support.

protected Task<string?> GetFileContentBase64Async(string? path)

Parameters

path string?
The relative path to the file in the web root.

Returns

Task<string?> The file content as a Base64 string, or null if the path is null or the file doesn't exist.