Installation
Add Doconut to your .NET Framework 4.7.2 web application
Doconut.NETFramework hosts the Doconut viewer in a classic ASP.NET application on .NET Framework 4.7.2 — IIS or IIS Express, MVC 5 or Web Forms. Setup has three parts: the NuGet package, two registrations in Web.config, and one call in Global.asax. This page covers all three; Quick Start then puts a document on a page.
Requirements
- The web project targets .NET Framework 4.7.2 or later. A 4.7 project cannot consume this package; retarget it first.
- The site runs in the integrated pipeline (the default for IIS and IIS Express application pools).
This page covers Doconut.NETFramework 26.9.0 and later. Versions 26.8.0 and earlier targeted .NET Framework 4.7 with a different API; that line is discontinued. Updating an existing application across that boundary is covered in Migration.
Install the package
From the Package Manager Console:
Install-Package Doconut.NETFrameworkOr, in an SDK-style project:
dotnet add package Doconut.NETFrameworkThe rendering engine is embedded in the package: there is no separate engine assembly to reference, copy, or deploy. Optional capabilities ship as their own packages — for example Doconut.NETFramework.Converter and Doconut.NETFramework.Dicom — and each one needs a license that grants it (see Plugin System).
Configure Web.config
Doconut serves two kinds of request, and IIS routes both through Web.config:
DocImage.axd— the viewer's page, thumbnail, search, and annotation endpoint, served byDoconut.DocImageHandler./doconut-res/*— the viewer's own scripts, stylesheets, and icons, embedded in the assembly and served byDoconut.DoconutResourceModule.
Add both, plus the settings they depend on:
<configuration>
<system.web>
<!-- MVC 5 only: Razor compiles views at run time and needs the netstandard facade. -->
<compilation targetFramework="4.7.2">
<assemblies>
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
</assemblies>
</compilation>
<!-- maxRequestLength is in KILOBYTES: 200 MB. -->
<httpRuntime targetFramework="4.7.2" maxRequestLength="204800" />
<!-- Read .cshtml and .aspx files as UTF-8, not as the server's ANSI code page. -->
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<!-- maxAllowedContentLength is in BYTES: the same 200 MB. -->
<requestLimits maxAllowedContentLength="209715200" />
</requestFiltering>
</security>
<modules runAllManagedModulesForAllRequests="true">
<add name="DoconutResourceModule" type="Doconut.DoconutResourceModule, Doconut" />
</modules>
<handlers>
<add name="DocImage" verb="GET,HEAD,POST" path="DocImage.axd"
type="Doconut.DocImageHandler, Doconut" />
</handlers>
</system.webServer>
</configuration>Each line prevents a failure that raises no exception:
verb="GET,HEAD,POST"— keepHEAD. The viewer sends aHEADrequest for page 1 to detect animated images. Without the verb, IIS answers404before the handler runs: documents still display, but animation detection never works and the browser console fills with 404s.runAllManagedModulesForAllRequests="true"—/doconut-res/*.js,.css, and.pnglook like static files, and IIS would hand them to its static file handler before the resource module sees them. The result is a viewer with no scripts or icons.<globalization fileEncoding="utf-8">— page files saved as UTF-8 without a byte-order mark are otherwise read with the server's ANSI code page, so every non-ASCII character reaches the browser double-encoded (an em dash shows as—). The file is correct on disk, and the page still declares<meta charset="utf-8">.- The
netstandardassembly (MVC 5) — Razor compiles views when they are first requested, with its own reference list that does not include this facade. A view that does anything dynamic beyond a plain member access then fails withCS0012and answers an empty500, and only the pages that trip it fail. The compiler error appears only in the Windows event log (source ASP.NET). Web Forms applications do not need this line. - Upload limits — ASP.NET reads the whole request body before any handler runs, so an upload above these limits is rejected by IIS with its own error page. Keep
maxRequestLength(kilobytes) andmaxAllowedContentLength(bytes) in step, and above the largest file your users open or upload.
Two more settings matter, and both are usually right already:
- Session state stays on. By default a page is served only to the ASP.NET session that opened the document, so the site must not set
<sessionState mode="Off" />. See Sessions & Security. - Binding redirects. Keep the
<runtime>binding redirects that NuGet writes intoWeb.config. In an SDK-style project, copy them from the generatedbin\<YourApp>.dll.config, because classic ASP.NET reads redirects only fromWeb.config. A redirect that names a version missing frombin\stops the whole application with an empty500at startup.
Register Doconut in Global.asax
There is no builder and no middleware pipeline in System.Web. Doconut is composed once per worker process by DoconutHost.Initialize in Application_Start, and released by DoconutHost.Shutdown in Application_End:
// Global.asax.cs
protected void Application_Start()
{
Doconut.DoconutHost.Initialize(options =>
{
options.LicensePath = HostingEnvironment.MapPath("~/wwwroot/Doconut.Viewer.lic");
});
}
protected void Application_End()
{
Doconut.DoconutHost.Shutdown();
}DoconutHost.Initialize builds the services the handler, the resource module, and your own code use. Your code reaches them through DoconutHost.Services (see DoconutHost). Only the first call configures anything; a second call is ignored. In an MVC application, also keep the two Doconut paths out of routing — Quick Start shows the complete Application_Start.
All options
DoconutOptions accepts the following settable properties. Every one is optional.
| Property | Default | Description |
|---|---|---|
UnsafeMode | false | When false, DocImage.axd serves a page only to the ASP.NET session that opened the document. When true, any request carrying the token is served. Leave it false. |
ShowDoconutInfo | false | When true, a DocImage.axd request with no token answers a version banner instead of 404. Useful as a smoke check; leave it off in production. |
ResourcesPath | "/doconut-res" | Where the resource module serves the embedded scripts, styles, and icons. Change it only together with the viewer's ResPath and any MVC IgnoreRoute. |
LicensePath | "" | Full path to the license file. Empty means fall through to the next source, then to automatic discovery. |
LicenseContent | "" | Raw license content — from an environment variable, a secret store, or a database. |
LicenseStream | null | License as a stream, read once at startup. |
MiddlewarePath | "/doconut" | Not used on this package. The page endpoint is the DocImage.axd handler declared in Web.config, whatever this is set to. It is still validated: it must start with / and differ from ResourcesPath. |
ResetLicense | false | Not used on this package. The license is read once, in DoconutHost.Initialize; recycle the application pool after replacing a license file. |
When more than one license source is set, LicenseStream beats LicenseContent, which beats LicensePath, which beats automatic discovery — see License Setup.
Doconut.DoconutHost.Initialize(options =>
{
options.LicensePath = HostingEnvironment.MapPath("~/wwwroot/Doconut.Viewer.lic");
options.ResourcesPath = "/doconut-res"; // where the viewer's JS/CSS/images are served from
options.UnsafeMode = false; // keep session security on
options.ShowDoconutInfo = false;
});
// The page endpoint is not an option here: it is the DocImage.axd handler declared in Web.config.Next steps
- Quick Start — open a document and render it in the browser, in MVC 5 or Web Forms.
- License Setup — where Doconut looks for your license file.
War diese Seite hilfreich?