ASP.NET Core Integration

HtmlForgeX.AspNetCore is the bridge package for service-hosted pages where you want HtmlForgeX to generate the HTML while ASP.NET Core serves the static libraries, antiforgery tokens, and upload progress endpoints.

Installation

dotnet add package HtmlForgeX.AspNetCore

Features

The ASP.NET Core package provides:

  • Embedded Asset Middleware — Serve HtmlForgeX CSS/JS files from embedded resources
  • Antiforgery Token Support — Generate forms with CSRF protection
  • Upload Progress Tracking — Track file upload progress with notifications
  • OfflineWithLinks support — Keep generated HTML small while still avoiding external CDNs

Minimal API Setup

builder.Services.AddHtmlForgeXAntiforgery();
builder.Services.AddHtmlForgeXUploadProgress();

var app = builder.Build();

app.MapHtmlForgeXEmbeddedAssets("/hfx");
app.MapHtmlForgeXUploadProgressApi("/hfx");

Configure Documents For Hosted Assets

using var doc = new Document();
doc.UseHtmlForgeXEmbeddedAssets("/hfx");

Generating HTML in Controllers

public IActionResult Report()
{
    var doc = new Document();
    doc.Body.Page(page => {
        page.Table<SalesRecord>(records);
    });
    return Content(doc.ToString(), "text/html");
}