InlineImgTagHelper Class
A TagHelper that inlines image files as Base64-encoded data URIs to reduce HTTP requests.
public sealed class InlineImgTagHelper : InlineTagHelperRemarks
This TagHelper is useful for embedding small images directly in HTML to eliminate additional HTTP requests. The image content is cached in memory and automatically invalidated when the source file changes.
Example
<inline-img src="logo.png" alt="Company Logo" />
@* Rendered as <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." alt="Company Logo" /> *@- Inheritance
InlineTagHelperInlineImgTagHelper
Constructors
| Name | Description |
|---|---|
| InlineImgTagHelper(IWebHostEnvironment, IMemoryCache, ILogger<InlineImgTagHelper>) | Initializes a new instance of the InlineImgTagHelper class. |
InlineImgTagHelper(IWebHostEnvironment, IMemoryCache, ILogger<InlineImgTagHelper>)
InlineImgTagHelper.csInitializes a new instance of the InlineImgTagHelper class.
public InlineImgTagHelper(IWebHostEnvironment webHostEnvironment, IMemoryCache cache, ILogger<InlineImgTagHelper> logger)Parameters
webHostEnvironmentIWebHostEnvironment- The web host environment for accessing web root files.
cacheIMemoryCache- The memory cache for storing file contents.
loggerILogger<InlineImgTagHelper>- The logger used to report missing files.
Properties
| Name | Description |
|---|---|
| Src | Gets or sets the path to the image file relative to the web root. |
Methods
| Name | Description |
|---|---|
| ProcessAsync(TagHelperContext, TagHelperOutput) | Processes the tag helper by converting the image source to an inline Base64 data URI. |
ProcessAsync(TagHelperContext, TagHelperOutput)
InlineImgTagHelper.csProcesses the tag helper by converting the image source to an inline Base64 data URI.
net10.0
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)net11.0
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)Parameters
contextTagHelperContext- Contains information about the current tag.
outputTagHelperOutput- A stateful HTML element used to generate an HTML tag.