Build a Self‑Hosted Document Viewer in .NET – Step‑by‑Step Guide
9/25/2026

Build a Self‑Hosted Document Viewer in .NET – Step‑by‑Step Guide

Learn how to embed a fast, secure, self‑hosted document viewer in a .NET app using the Doconut SDK and deliver PDF, Office, CAD previews without external services.

You’ll have a self‑hosted, lightning‑fast document viewer running inside your .NET application

By the end of this guide you can open PDFs, Office files, CAD drawings and dozens of other formats directly in the browser, with sub‑second load times, no external SaaS calls, and full control over security.


Prerequisites

What you needWhy it matters
.NET 6 or later (the SDK targets .NET 6+)Guarantees compatibility with the Online Document Viewer SDK
A Windows or Linux server where you can run your application (on‑premise or private cloud)Self‑hosting requires the viewer to live inside your own infrastructure
Access to the Online Document Viewer NuGet feed (https://doconut.com)The SDK is distributed as a NuGet package
Basic knowledge of ASP.NET Core and front‑end JavaScriptYou’ll expose an endpoint that returns a signed URL and then launch the viewer from the browser
A storage location for the source files (file system, blob storage, etc.)The viewer renders files from a local or network path; the source must be reachable by the server process

Missing any of these items will cause the build to stall before the first line of code runs.


Install the Online Document Viewer SDK

Open your solution in Visual Studio or your preferred IDE and add the official SDK via the NuGet manager:

dotnet add package Doconut.NET8

The package contains the rendering engine, format converters and a thin HTTP layer that serves the generated pages. Because the SDK is compiled into your application, no external service is contacted at runtime.

After the package is restored, register the SDK services in Program.cs (or Startup.cs for older templates). The registration injects the rendering pipeline into the ASP.NET Core DI container, making it available to your controllers.


Configure the rendering pipeline for the required formats

The viewer supports more than 50 formats out of the box, including:

  • PDF, DOC, DOCX, ODT, RTF
  • XLS, XLSX, CSV, ODS
  • PPT, PPTX, ODP
  • DWG, DXF, DGN (CAD)
  • PSD, SVG, TIFF, WEBP, ICO
  • EML, MSG, EPUB, MOBI, MPP, VSD

When a request arrives, the SDK determines the file type and selects the appropriate converter. For best performance, enable the built‑in caching layer that stores the rendered page in memory for the duration of the request; this is what gives the “Lightning Fast – Instant document rendering with optimized performance and sub‑second loading” experience.

In your controller, call the SDK’s rendering method (e.g., RenderAsync) and pass the absolute path of the source file. The method returns an HTML fragment that contains a canvas‑based viewer. Because rendering happens on the server, the client only receives ready‑to‑display markup, which eliminates heavy client‑side processing.


Secure the viewer with token‑based URLs and optional restrictions

Data sovereignty and GDPR compliance are common concerns for on‑premise deployments. The SDK integrates with ASP.NET Core’s authentication system, allowing you to generate a signed token that grants one‑time access to a specific document.

Typical flow:

  1. The front‑end asks your API for a preview token, providing the document identifier.
  2. Your API validates the user’s permissions, creates a JWT‑style token that encodes the file path and an expiration timestamp, and returns the token.
  3. The front‑end appends the token to the viewer URL (e.g., /viewer?token=…). The SDK validates the token on each request and rejects any tampered or expired token.

If you need to prevent users from downloading or printing the document, configure the rendering options provided by the SDK to disable those actions. The viewer’s JavaScript layer will then hide the download button, suppress the print shortcut, and block the right‑click context menu.


Verify that everything works

  1. Navigate to the page that hosts the viewer.
  2. The document should appear within a second, with scrollbars, zoom controls and a search box.
  3. If you configured the viewer to disable download, the “Download” button should be hidden.
  4. Right‑clicking on the document should not open the browser context menu when that restriction is enabled.
  5. After the token expires (default is 5 minutes), refreshing the page should return a “401 Unauthorized” error, confirming that token validation is active.

If any of these checks fail, revisit the corresponding step: missing SDK registration, incorrect token generation, or omitted security flags.