gpt4 book ai didi

c# - 如何在 Azure 中为 .NEt 核心应用程序应用 woff 字体?

转载 作者:行者123 更新时间:2023-12-03 01:40:32 30 4
gpt4 key购买 nike

我有一个 .Net Core MVC 应用程序,它使用 DinkToPdf(包装 libwkhtmltox.dll)从 HTML 创建 PDF 文件。我使用的字体之一是 .woff 字体,这在我的本地计算机上运行良好。但是在 Azure 中,不应用该字体。

我读过其他线程,指出应将 mimeType 添加到 .Net Core 的 FileExtensionContentTypeProvider 中,而不是添加到 .Net 应用程序中的 web.config 中。

var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".woff"] = "font/woff";
provider.Mappings[".ttf"] = "font/ttf";
provider.Mappings[".otf"] = "font/otf";
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "fonts")),
RequestPath = "/fonts",
ContentTypeProvider = provider
});

我也尝试过不同的 mimeTypes,但相信这些是正确的。您可以看到我还添加了 .ttf 和 .otf 来查看 Azure 是否存在其中一个问题,而另一个没有问题。然后我按照下面的方式引用 css 中的字体...

@font-face {
font-family: 'barcode';
src: url(../fonts/fre3of9x.woff) format('woff'), url(../fonts/fre3of9x.ttf) format('ttf'), url(../fonts/CODE39.otf) format('otf');
font-weight: normal;
font-style: normal; }

我在 Azure 中看不到任何可以设置的内容,所以我遇到了麻烦。有人可以帮忙吗?

最佳答案

我假设您正在使用的 Azure 应用服务基本上只是 IIS。 IIS 不提供对 WOFF 的现成支持。这将要求您将 web.config 添加到项目的根目录,并确保将其部署到应用服务。以下是 web.config 中需要包含的内容。

<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".woff" mimeType="font/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="font/font-woff" />
</staticContent>
</system.webServer>
</configuration>

希望这有帮助。

您可能必须显式删除扩展并将其添加回来。这是我在一些我知道有效的网站中使用的方法。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff" mimeType="font/font-woff" />
<mimeMap fileExtension=".woff2" mimeType="font/font-woff" />
</staticContent>
</system.webServer>
</configuration>

关于c# - 如何在 Azure 中为 .NEt 核心应用程序应用 woff 字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54128265/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com