ASP.NET Core Applications
A Razor Pages or MVC application shows the spreadsheet editor with the Tag Helper of the package TXTextControl.TXSheetControl.AspNetCore. The package brings the editor script and its fonts as static web assets: dotnet publish copies them into the output, and the static file middleware of the application serves them. Backend processing needs the separate Server package, TXTextControl.TXSheetControl.Server; the editor does not.
Configure the Middleware
The application serves the editor's files with the ordinary static file middleware:
using TXTextControl.TXSheetControl.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
var app = builder.Build();
app.UseTXSheetControlAssets();
app.UseStaticFiles();
app.MapRazorPages();
app.Run();
- Static files.
UseStaticFilesserves the editor's files. TheMapStaticAssetscall of the .NET 10 project templates works as well; keep the one your project uses. - UseTXSheetControlAssets. Call it before
UseStaticFilesorMapStaticAssets. It rejects requests for private and debugging paths of the package before the static file middleware answers them. It does not serve files itself: without static files, the editor's scripts return 404. UseStaticWebAssets. A published application does not needbuilder.WebHost.UseStaticWebAssets(). It matters only when you run the build output, not the publish output, in an environment other than Development, as the Getting Started example does.
What the Tag Helper Loads
The Tag Helper writes the configuration of the editor into the page and adds two deferred scripts, once per page, also for several editors:
_content/TXTextControl.TXSheetControl.AspNetCore/tx-sheet-control.min.js, the editor, with a?v=version for caching._content/TXTextControl.TXSheetControl.AspNetCore/tx-sheet-control-init.min.js, which creates the editors of the page.
The editor then loads fonts/catalog.json and the fonts it needs from the same folder. The styles are part of the script and installed inside the editor's Shadow DOM, so the page needs no <link> element. Remove any manual <script> or <link> references to these files from older pages.
Publish the Application
dotnet publish Release publish
Deploy the complete publish folder. It contains the package files in wwwroot/_content/TXTextControl.TXSheetControl.AspNetCore/: the scripts, fonts/ with the catalog, the fonts and their notices, languages/ and licenses/, each also as a precompressed .br and .gz copy. Run the application from that folder; it needs no Server package, no font service and no registration of services for the editor.
Run Below a Path Base
When the application runs below a path, such as https://example.com/reports/, configure the path base before the static file middleware, for example with app.UsePathBase("/reports") or the settings of your reverse proxy. The Tag Helper then writes all URLs with the path, such as /reports/_content/TXTextControl.TXSheetControl.AspNetCore/tx-sheet-control.min.js, and the editor loads its fonts from there. A custom FontCatalogURL and your own scripts must include the path as well.
Optional Font Routes
MapTXSheetControlFonts redirects the URLs /sheet-fonts/…, below the default catalog URL of the JavaScript editor, to the fonts of the package, such as /sheet-fonts/catalog.json to /_content/TXTextControl.TXSheetControl.AspNetCore/fonts/catalog.json. Pages with the Tag Helper do not need it. Use it when other scripts of your application create editors without setting fontCatalogURL.
Use the Editor From Your Scripts
The editor exists only after the init script has run. Subscribe to the txsheetcontrolready and txsheetcontrolerror events, which bubble from the editor's element, before the scripts run, and use the Spreadsheet control in event.detail:
<script>
document.addEventListener('txsheetcontrolready', event => {
const editor = event.detail;
editor.workbook.sheets.at(0).cell('A1').setText('Ready');
});
</script>
Verify the Published Application
Open the published application in a browser and check:
- The editor appears and the browser console shows no errors.
- The requests for
tx-sheet-control.min.js,catalog.jsonand the fonts return 200, below the path base if there is one. - A formula calculates, and a PDF export contains the expected fonts and no watermark of the wrong license.
- A page with two editors works.
Next Steps
- Licensing: configure the license in
TXSheetControlOptions.License. - Custom Fonts: point the Tag Helper at a catalog of your own with
FontCatalogURL. - Host Security and File Handling: align the Tag Helper's scripts with the content security policy of your application.