Embedded Assets & Upload Progress
HtmlForgeX.AspNetCore is designed for hosted apps where you want HtmlForgeX to emit small HTML documents and let ASP.NET Core serve the required CSS, JavaScript, fonts, and helper endpoints.
Why Use It
- Avoid giant inline payloads when generating many pages dynamically
- Keep vendor assets inside your application instead of relying on public CDNs
- Reuse HtmlForgeX antiforgery defaults across forms and XHR uploads
- Add upload progress APIs without writing a custom JavaScript layer
Minimal API Setup
using HtmlForgeX.AspNetCore;
builder.Services.AddHtmlForgeXAntiforgery();
builder.Services.AddHtmlForgeXUploadProgress();
var app = builder.Build();
app.MapHtmlForgeXEmbeddedAssets("/hfx");
app.MapHtmlForgeXUploadProgressApi("/hfx");With that in place, HtmlForgeX can emit links such as:
/hfx/styles/tabler.min.css/hfx/scripts/tabler.min.js/hfx/uploads/{id}
Configure Generated Documents
Use linked assets instead of fully inlined output:
using var doc = new Document();
doc.UseHtmlForgeXEmbeddedAssets("/hfx");This pairs naturally with LibraryMode.OfflineWithLinks , which keeps HTML output small while still staying self-hosted.
Antiforgery
HtmlForgeX uses the same defaults in forms and XHR helpers:
- hidden field:
csrf - request header:
X-CSRF-Token
var csrf = httpContext.GetAndStoreHtmlForgeXCsrfToken(antiforgery);
doc.UseHtmlForgeXAntiforgery(csrf);
form.UseHtmlForgeXAntiforgery(csrf);Upload Progress
The package also ships an in-memory upload progress store plus a GET /hfx/uploads/{id} API. That gives Dropzone-style flows a typed server-side integration point without adding app-specific front-end plumbing for every project.
Operational Notes
- Only HtmlForgeX embedded resources are exposed, not arbitrary files from disk
- Responses are cache-friendly with long-lived cache headers and
ETag - Your application still controls access to the pages that consume those assets
Related Guides
- ASP.NET Core Integration — package overview and controller usage
- Hosting Sample — end-to-end sample built around dynamic transfers