When using the NuGet package for the TX Text Control document editor, static files must be added to serve JavaScript, CSS and resource files.

Adding Static Files

Adding TX Text Control to an ASP.NET Core Razor Pages application is the same like for MVC applications. If you create a new ASP.NET Core Web Application based on our tutorial, the following configuration code is added to the Startup.cs:

// serve static linked files (JavaScript and CSS for the editor)
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
System.IO.Path.Combine(System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetEntryAssembly().Location),
"TXTextControl.Web")),
RequestPath = "/TXTextControl.Web"
});
view raw startup.cs hosted with ❤ by GitHub

In the above code, the TXTextControl.Web directory hierarchy is publicly available in the TXTextControl.Web URI segment. The request to http://<server_address>/TXTextControl.Web/JS/tx-min.js serves the tx-min.js file.

This concept works very well for MVC applications where a controller is routing the requests to the views and the above static file requests are always routed to the root folder.

Razor Pages

With Razor Pages, by convention, associations of URL paths to pages are determined by the page's location in the file system. This tutorial shows how to create a simple ASP.NET Core Razor Pages application. The content of the various segments is stored in folders named after the pages. The following screenshot shows this structure with folders for the available pages TestPage, TestPage2 and TestPage3:

TX Text Control in Razor

Now, the resource request for the static files for TestPage is:

http://<server_address>/TestPage/TXTextControl.Web/JS/tx-min.js

In order to solve this routing, another entry in the Startup.cs is required:

app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
System.IO.Path.Combine(System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetEntryAssembly().Location),
"TXTextControl.Web")),
RequestPath = "/TestPage/TXTextControl.Web",
});
view raw startup.cs hosted with ❤ by GitHub

Pay attention to the RequestPath property that contains the page name as the first segment. Repeat this for all pages where TX Text Control is used to get the resources loaded properly.