[英]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.