繁体   English   中英

如何在Azure for .NEt核心应用程序中应用woff字体?

[英]How can i apply woff fonts in Azure for .NEt core app?

我有一个.Net Core MVC应用程序,该应用程序使用DinkToPdf(包装libwkhtmltox.dll)来从HTML创建PDF文件。 我正在使用的一种字体是.woff字体,在我的本地计算机上可以正常工作。 但是,在Azure中,不会应用字体。

我已经阅读了其他线程,其中指出应将mimeTypes添加到.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
        });

我也尝试了不同的mimeType,但是相信这些是正确的。 您可以看到我还添加了.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添加到项目的根目录,并确保将其部署到App Service。 这是需要在web.config中的内容。

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/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="application/font-woff" />
    <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
  </staticContent>
  </system.webServer>
</configuration>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM