This article shows how to create a simple ASP.NET Core application using the Document Editor and deploy it in a Docker container on Linux. The article shows how to use the NuGet packages and how to deploy the Web server in a Docker container.
TX Text Control supports most popular Linux distributions and can be run in VMs, Docker containers, or any hyperscaler environment such as Azure App Services, AWS Elastic Beanstalk, or Google Cloud Run.
This tutorial shows how to create an ASP.NET Core Web application that hosts TX Text Control in a standard Linux container using the default Visual Studio template.
Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the .NET 8 SDK.
1. In Visual Studio 2022, create a new project by choosing Create a new project.
2. Select ASP.NET Core Web App (Model-View-Controller) as the project template and confirm with Next.
3. Enter a project name and choose a location to save the project. Confirm with Next.
4. Choose .NET 8.0 (Long Term Support) as the Framework.
5. Enable the Enable container support checkbox and choose Linux as the Container OS.
6. Choose Dockerfile for the Container build type option and confirm with Create.

7. Create a new class named TXWebServerProcess.cs and replace the content with the provided code.
using System.Diagnostics;
using System.Reflection;
public class TXWebServerProcess : IHostedService
{
private readonly ILogger<TXWebServerProcess> _logger;
public TXWebServerProcess(ILogger<TXWebServerProcess> logger) => _logger = logger;
public Task StartAsync(CancellationToken cancellationToken)
{
try
{
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string dllPath = Path.Combine(path ?? "", "TXTextControl.Web.Server.Core.dll");
if (string.IsNullOrEmpty(path) || !File.Exists(dllPath))
_logger.LogWarning("TX Web Server process could not be started.");
else
{
Process.Start(new ProcessStartInfo("dotnet", $""{dllPath}" &") { UseShellExecute = true, WorkingDirectory = path });
_logger.LogInformation("TX Web Server process started.");
}
}
catch (Exception ex) { _logger.LogError(ex, "Error starting TX Web Server."); }
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Stopping TX Web Server process...");
return Task.CompletedTask;
}
}8. Now right-click the project in the Solution Explorer and choose Add -> Existing Item.... Navigate to the installation folder of TX Text Control .NET Server for ASP.NET.
C:\Program Files\Text Control GmbH\TX Text Control 34.0.NET Server for ASP.NET\Assembly\net8.0
Set the file filter to All Files (*.*) and select the following files:
Confirm with Add.
9. Set the Copy to Output Directory property to Copy always for the added files.
10. In the Solution Explorer, select your project and choose Manage NuGet Packages... from the Project menu.
Install the following packages:

11. Open Program.cs and add the necessary configuration code.
After builder.Services.AddControllersWithViews();, add the following code:
builder.Services.AddHostedService<TXWebServerProcess>();At the very top of the file, insert the following code:
using TXTextControl.Web;Add the following code after the entry app.UseStaticFiles();:
// enable Web Sockets
app.UseWebSockets();
// attach the Text Control WebSocketHandler middleware
app.UseTXWebSocketMiddleware();The overall Program.cs file should look like the provided example.
using TXTextControl.Web;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddHostedService<TXWebServerProcess>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
// enable Web Sockets
app.UseWebSockets();
// attach the Text Control WebSocketHandler middleware
app.UseTXWebSocketMiddleware();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();12. Find Index.cshtml in Views -> Home and replace its content with the document editor code.
@using TXTextControl.Web.MVC
@{
var sDocument = "<html><body><p>Welcome to <strong>Text Control</strong></p></body></html>";
}
@Html.TXTextControl().TextControl(settings => {
settings.UserNames = new string[] { "Tim Typer" };
}).LoadText(sDocument, TXTextControl.Web.StringStreamType.HTMLFormat).Render()
<input type="button" onclick="insertTable()" value="Insert Table" />
<script>
function insertTable() {
TXTextControl.tables.add(5, 5, 10, function(e) {
if (e === true) { // if added
TXTextControl.tables.getItem(function(table) {
table.cells.forEach(function(cell) {
cell.setText("Cell text");
});
}, null, 10);
}
})
}
</script>We will use the Dockerfile as is and use the default Visual Studio template using a Linux container from the official Docker Hub repository.
13. Start the application by pressing F5 or by choosing Debug -> Start Debugging from the main menu.