# Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor and Viewer

> This article shows how to create a backend for the Document Editor and Viewer using ASP.NET Core. The backend can be hosted on Windows and Linux and can be used in Blazor, Angular, JavaScript, and ASP.NET Core applications.

- **Author:** Bjoern Meyer
- **Published:** 2025-03-26
- **Modified:** 2025-11-16
- **Description:** This article shows how to create a backend for the Document Editor and Viewer using ASP.NET Core. The backend can be hosted on Windows and Linux and can be used in Blazor, Angular, JavaScript, and ASP.NET Core applications.
- **6 min read** (1025 words)
- **Tags:**
  - ASP.NET
  - ASP.NET Core
  - Blazor
  - Document Viewer
  - Document Editor
  - Angular
- **LLMs.txt URL:** https://www.textcontrol.com/blog/2025/03/26/building-an-asp-net-core-backend-for-the-document-editor-and-viewer/llms.txt
- **LLMs-full.txt URL:** https://www.textcontrol.com/blog/2025/03/26/building-an-asp-net-core-backend-for-the-document-editor-and-viewer/llms-full.txt
- **Canonical URL:** https://www.textcontrol.com/blog/2025/03/26/building-an-asp-net-core-backend-for-the-document-editor-and-viewer/

---

In this tutorial, we'll walk you through building a cross-platform ASP.NET Core backend (targeting .NET 8 and beyond) specifically designed to host the TX Text Control Document Editor and Document Viewer.

Whether you're running on Windows or Linux, on-premises or in a containerized environment using Docker or Kubernetes, this backend setup gives you the flexibility to integrate powerful document editing and viewing capabilities into your applications without locking you into a specific operating system or infrastructure.

By the end of this guide, you'll have a robust, production-ready backend that provides rich document handling capabilities while taking advantage of the performance and cross-platform benefits of .NET 8.

> ### Prerequisites
> 
> You need to download and install the trial version of TX Text Control .NET Server to get access to the required NuGet packages.
> 
> - [Download Trial Version](https://www.textcontrol.com/product/tx-text-control-dotnet-server/download/)  
>     Setup download and installation required.

### Creating the Application

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0).

1. In Visual Studio 2022, create a new project by choosing *Create a new project*.
2. Select *ASP.NET Core Web API* as the project template and confirm with *Next*.
3. Choose a name for your project and confirm with *Next*.
4. In the next dialog, choose *.NET 8 (Long Term Support)* as the *Framework*, select *Enable container support* if required, check *Use controllers*, and confirm with *Create*.
    
    ![Creating the .NET 8 project](https://s1-www.textcontrol.com/assets/dist/blog/2025/03/26/a/assets/visualstudio1.webp "Creating the .NET 8 project")

#### Adding the Web Server Backend

5. Create a new class by right-clicking the project in the *Solution Explorer* and choose *Add -> Class...*. Name the class *TXWebServerProcess.cs* and confirm with *Add*. Replace the complete content with the following 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;
    }
    }
    ```
6. 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:
    
    *C:\\Program Files\\Text Control GmbH\\TX Text Control 33.0.NET Server for ASP.NET\\Assembly\\net8.0*
    
    Set the file filter to *All Files (\*.\*)* and select the following files:
    
    
    - *TXTextControl.Web.Server.Core.deps.json*
    - *TXTextControl.Web.Server.Core.dll*
    - *TXTextControl.Web.Server.Core.Process.deps.json*
    - *TXTextControl.Web.Server.Core.Process.dll*
    - *TXTextControl.Web.Server.Core.Process.runtimeconfig.json*
    - *TXTextControl.Web.Server.Core.runtimeconfig.json*
    - *TXTextControl.Web.Server.Core.config.json*
    
    Confirm with *Add*.
7. Select the added files in the *Solution Explorer* and set the *Copy to Output Directory* property to *Copy always*.

#### Adding the NuGet Packages

8. In the *Solution Explorer*, select your created project and choose *Manage NuGet Packages...* from the *Project* main menu. Select **Text Control Offline Packages** as the *Package source*.
    
    Install the following packages:
    
    
    - **TXTextControl.Web**
    - **TXTextControl.Web.DocumentViewer**
    - **TXTextControl.TextControl.Core.SDK**
    
    ![ASP.NET Core Web Application](https://s1-www.textcontrol.com/assets/dist/blog/2025/03/26/a/assets/visualstudio2.webp "ASP.NET Core Web Application")

#### Configure the Application

9. Open the *Program.cs* file located in the project's root folder and replace the code with the following:
    
    ```
    using TXTextControl.Web;
    using TXTextControl.Web.MVC.DocumentViewer;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // Add services to the container.
    builder.Services.AddControllers();
    builder.Services.AddHostedService<TXWebServerProcess>();
    
    // *** Required for Document Viewer ***
    builder.Services.AddCors(p => p.AddPolicy("corsapp", builder =>
    {
    builder.WithOrigins("*").AllowAnyMethod().AllowAnyHeader();
    }));
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    
    app.UseHttpsRedirection();
    
    app.UseAuthorization();
    
    app.MapControllers();
    
    // *** Required for Document Editor ***
    // add the WebSocket middleware
    app.UseWebSockets();
    app.UseTXWebSocketMiddleware();
    
    // *** Required for Document Viewer ***
    // add the DocumentViewer middleware
    app.UseCors("corsapp");
    app.UseRouting();
    app.UseTXDocumentViewer();
    
    app.Run();
    ```

> **Learn More**
> 
> This article describes how to configure the TX Text Control Document Editor Backend Web Server, including port and logging settings.
> 
> [Configuring the TX Text Control Document Editor Backend Web Server, including Port and Logging ](https://www.textcontrol.com/blog/2025/03/28/configuring-the-tx-text-control-document-editor-backend-web-server-including-port-and-logging/llms-full.txt)

#### Running the Backend

Press *F5* to start the application. The backend is now running and listening on the port that is defined the in the *\[your-application-name\].http* file.

The default Visual Studio template uses a sample controller that returns a list of weather forecasts. You can remove this controller and replace it with one of your own.

Now, you have a fully functional ASP.NET Core backend that is ready to host the TX Text Control Document Editor and Document Viewer.

### Connecting the Frontend

Now that the backend is running, you can connect the frontend to the backend. The frontend can be any client-side framework such as Angular, React, or JavaScript.

#### Connecting JavaScript

For JavaScript, you can use the following code to connect the Document Editor to the backend:

```

<html>
<head>
<meta charset="utf-8" />
<title>TX Text Control Document Editor from JS</title>
<script 
src="https://localhost:32769/api/TXWebSocket/GetResource?name=tx-document-editor.min.js">
</script>
<style>
#txDocumentEditor {
height: 800px;
width: 800px;
}
</style>
</head>
<body>

<div id="txDocumentEditor"></div>

<script type="module">
TXTextControl.init({
containerID: "txDocumentEditor",
webSocketURL: "wss://localhost:32769/api/TXWebSocket"
});

var documentString = "Hey - it compiles! <strong>Ship it!</strong>";

TXTextControl.addEventListener("textControlLoaded", function () {
TXTextControl.loadDocument(TXTextControl.StreamType.HTMLFormat, btoa(documentString));
});
</script>

</body>
</html>
```

Make sure to adjust the URL to the backend that is running on your machine.

To connect the Document Viewer, use the following code:

```

<html>
<head>
<meta charset="utf-8" />
<title>TX Text Control Document Viewer from JS</title>
<script src="https://localhost:32769/TextControl/GetResource?Resource=minimized.tx-viewer.min.js"></script>
<script src="https://localhost:32769/TextControl/GetResource?Resource=minimized.tx-viewer-component.min.js"></script>
<style>
#txDocumentViewer {
height: 800px;
width: 800px;
}
</style>
</head>
<body>

<tx-document-viewer
id="viewer1"
settings='{"documentData":"VGV4dCBDb250cm9s", "dock":1, "basePath":"https://localhost:32769"}'>
</tx-document-viewer>

</body>
</html>
```

#### Connecting Angular

For Angular, you can use the following code to connect the Document Editor to the backend:

```
<tx-document-editor
width="1000px"
height="800px"
webSocketURL="wss://localhost:5260/TXWebSocket"
statusBarColor="#FF00FF"
[controlChars]="true"
[userNames]="['Tim Typer']">
</tx-document-editor>
```

Pay attention to the protocol *wss* that is required for the WebSocket connection.

To connect the Document Viewer, use the following code:

```
<tx-document-viewer
width="1000px"
height="800px"
basePath="http://localhost:5260"
dock="Window"
[toolbarDocked]="true"
documentPath="demo.docx"
[isSelectionActivated]="true"
[showThumbnailPane]="true">
</tx-document-viewer>
```

#### Backend Deployment

This backend can be deployed to any hosting provider that supports ASP.NET Core applications. You can deploy it to Azure, AWS, or any other cloud provider as a VM, container or as a serverless service.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [TX Text Control Document Editor and Viewer for Blazor Released](https://www.textcontrol.com/blog/2025/03/25/tx-text-control-document-editor-and-viewer-for-blazor-released/llms.txt)
- [Announcing Our Work on a Blazor Component for Document Editing and Viewing](https://www.textcontrol.com/blog/2025/01/24/announcing-our-work-on-a-blazor-component-for-document-editing-and-viewing/llms.txt)
- [Building an ASP.NET Core Backend Application to Host the Document Editor and Document Viewer](https://www.textcontrol.com/blog/2024/03/14/building-an-asp-net-core-backend-application-to-host-the-document-editor-and-document-viewer/llms.txt)
- [TX Text Control for Blazor: Mail Merge Integration Tutorial](https://www.textcontrol.com/blog/2025/03/25/tx-text-control-for-blazor-mail-merge-integration-tutorial/llms.txt)
- [Getting Started: Document Editor for Blazor in ASP.NET Core](https://www.textcontrol.com/blog/2025/03/25/getting-started-document-editor-for-blazor-in-asp-net-core/llms.txt)
- [Getting Started: Document Viewer for Blazor in ASP.NET Core](https://www.textcontrol.com/blog/2025/03/25/getting-started-document-viewer-for-blazor-in-asp-net-core/llms.txt)
- [Preparing Documents for E-Signing for Multiple Signers in .NET C#](https://www.textcontrol.com/blog/2024/11/13/preparing-documents-for-e-signing-for-multiple-signers-in-net-c-sharp/llms.txt)
- [ASP.NET Core: Use the Document Editor and Viewer in the Same Razor View](https://www.textcontrol.com/blog/2024/11/08/asp-net-core-use-the-document-editor-and-viewer-in-the-same-razor-view/llms.txt)
- [Observe When the Reporting Preview Tab is Active Using MutationObserver](https://www.textcontrol.com/blog/2024/07/23/observe-when-the-reporting-preview-tab-is-active-using-mutationobserver/llms.txt)
- [Adding a Security Middleware to ASP.NET Core Web Applications to Protect TX Text Control Document Editor and Document Viewer Endpoints](https://www.textcontrol.com/blog/2024/03/18/adding-a-security-middleware-to-asp-net-core-web-applications-to-protect-tx-text-control-document-editor-and-document-viewer-endpoints/llms.txt)
- [Introducing Text Control Agent Skills](https://www.textcontrol.com/blog/2026/03/27/introducing-text-control-agent-skills/llms.txt)
- [Deploying the TX Text Control Document Editor from the Private NuGet Feed to Azure App Services (Linux and Windows)](https://www.textcontrol.com/blog/2026/03/25/deploying-the-tx-text-control-document-editor-from-the-private-nuget-feed-to-azure-app-services-linux-and-windows/llms.txt)
- [Build a Custom Backstage View in ASP.NET Core with TX Text Control](https://www.textcontrol.com/blog/2026/02/17/build-a-custom-backstage-view-in-aspnet-core-with-tx-text-control/llms.txt)
- [ASP.NET Core Document Editor with Backend via the Text Control Private NuGet Feed](https://www.textcontrol.com/blog/2026/02/09/aspnet-core-document-editor-private-nuget-feed/llms.txt)
- [Why Document Processing Libraries Require a Document Editor](https://www.textcontrol.com/blog/2025/12/04/why-document-processing-libraries-require-a-document-editor/llms.txt)
- [High-Performance Text Replacement in Large DOCX Files using C# .NET](https://www.textcontrol.com/blog/2025/07/30/high-performance-text-replacement-in-large-docx-files-using-csharp-dotnet/llms.txt)
- [Document Viewer 33.2.1 Released: New Event and Bug Fixes](https://www.textcontrol.com/blog/2025/07/30/document-viewer-33-2-1-released-new-event-and-bug-fixes/llms.txt)
- [Getting Started Video Tutorial: Document Editor in ASP.NET Core C# on Linux](https://www.textcontrol.com/blog/2025/07/29/getting-started-video-tutorial-document-editor-aspnet-core-csharp-linux/llms.txt)
- [E-Sign Comes to Blazor: Document Viewer 33.0.1 Released](https://www.textcontrol.com/blog/2025/04/24/e-sign-comes-to-blazor-document-viewer-33-0-1-released/llms.txt)
- [Deploying the TX Text Control Document Editor in an ASP.NET Core Web App to Azure App Services](https://www.textcontrol.com/blog/2025/03/26/deploying-the-tx-text-control-document-editor-in-an-asp-net-core-web-app-to-azure-app-services/llms.txt)
- [Introducing TXTextControl.Web.Server.Core: A Cross-Platform Backend for TX Text Control Document Editor](https://www.textcontrol.com/blog/2025/03/13/introducing-txtextcontrol-web-server-core-a-cross-platform-backend-for-tx-text-control-document-editor/llms.txt)
- [Getting Started: Document Editor with ASP.NET Core and Docker Support with Linux Containers](https://www.textcontrol.com/blog/2025/03/12/getting-started-document-editor-with-asp-net-core-and-docker-support-with-linux-containers/llms.txt)
- [Changing the Language in the Angular Document Editor Using the Resource Kit](https://www.textcontrol.com/blog/2025/03/05/changing-the-language-in-the-angular-document-editor-using-the-resource-kit/llms.txt)
- [Impressions from .NET Developer Conference DDC 2024](https://www.textcontrol.com/blog/2024/11/28/impressions-from-net-developer-conference-ddc-2024/llms.txt)
- [Back from Florida: Impressions from VSLive! Orlando 2024](https://www.textcontrol.com/blog/2024/11/21/back-from-florida-impressions-from-vslive-orlando-2024/llms.txt)
