简体   繁体   English

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

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

I ahve a .Net Core MVC app that uses DinkToPdf, which wraps libwkhtmltox.dll, to create PDF files from HTML. 我有一个.Net Core MVC应用程序,该应用程序使用DinkToPdf(包装libwkhtmltox.dll)来从HTML创建PDF文件。 One of the fonts i am using is a .woff font and this works fine on my local machine. 我正在使用的一种字体是.woff字体,在我的本地计算机上可以正常工作。 However in Azure, the font is not applied. 但是,在Azure中,不会应用字体。

I have read other threads that state the mimeTypes should be added to FileExtensionContentTypeProvider ofr .Net Core as opposed to the web.config in .Net apps. 我已经阅读了其他线程,其中指出应将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
        });

I have also tried the different mimeTypes, but believ these are the correct ones. 我也尝试了不同的mimeType,但是相信这些是正确的。 You can see i ahve also added .ttf and .otf to see if Azure had a problem with one and not the other. 您可以看到我还添加了.ttf和.otf,以查看Azure是否有问题而不是其他问题。 I am then referenceing the font in css as per below... 然后我按如下引用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; }

I can't see anything in Azure that i can set so i have hit a brick wall. 我看不到Azure可以设置的任何内容,所以我碰到了砖墙。 Can anyone help? 有人可以帮忙吗?

Azure App Service, which I assume you are using, is basically just IIS. 我假设您正在使用的Azure应用服务基本上只是IIS。 IIS doesn't have support for WOFF out of the box. IIS没有开箱即用的WOFF支持。 This will require you to add a web.config to the root of your project and make sure that it gets deployed to the App Service. 这将需要您将web.config添加到项目的根目录,并确保将其部署到App Service。 Here is what will need to be in the web.config. 这是需要在web.config中的内容。

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

Hope this helps. 希望这可以帮助。

You may have to explicitly remove the extensions and add them back. 您可能必须显式删除扩展并将其重新添加。 This is the one I use in a few websites that I know works. 这是我在几个我知道有效的网站中使用的网站。

<?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.

相关问题 如何检索Azure Web App上托管的.NET Core中的AD用户名? - How can I retrieve AD Username in .NET Core hosted on Azure Web App? 我如何在Webjob内的Azure托管ASP .NET Core应用程序的wwwroot文件夹中获取图像文件的路径 - How can i get the path to an image file in wwwroot folder of an azure hosted asp .net core app inside a webjob 如何从 Azure 应用服务连接字符串设置 ASP.Net Core exe.config 值 - How can I set an ASP.Net Core exe.config value from Azure App Service Connection String 当托管在Azure应用程序服务中时,如何控制添加到ASP.NET核心Web应用程序中的HTTP响应标头? - How can I control the HTTP response headers added to my ASP.NET core web application when hosted in Azure app service? 如何在 .NET Core 2.2 应用程序中创建 CloudTableClient? - How can I create a CloudTableClient in .NET Core 2.2 app? 我如何在 dot net Core 中安排应用程序 dll 文件 - How can i Arrange app dll files in dot net Core 如何检查我的应用程序与.net核心的兼容性? - How can I check the compatibility of my app against .net core? 如何将 Azure AD 和非 Azure AD 令牌添加到同一个 .NET 核心 Z72664DC1959F3B0C047C048 - How I can add both Azure AD and non Azure AD tokens to the same .NET Core Api 不能与.Net Core App中的Azure Blob存储一起使用 - Can't work with Azure Blob Storage from .Net Core App 我可以使用哪个.NET对象将文件从WPF桌面应用程序移动(流式传输)到Azure Webapp(.NET Core 2)? - Which .NET object can I use to move(stream?) a file from a WPF desktop app to an Azure webapp (.NET Core 2)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM