[英]How can I retrieve AD Username in .NET Core hosted on Azure Web App?
[英]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.