【问题标题】:loading web fonts in asp.net website在 asp.net 网站中加载网络字体
【发布时间】:2012-11-03 06:59:40
【问题描述】:

我一直在做 asp.net 网站开发,但从未实现过完整的 asp.net 网站并托管它。我一直在开发一个 asp.net 网站并将其托管在 windows 服务器上。

我有几个在网站中使用的自定义网络字体(付费字体)。我已经在我的项目文件夹中包含了网络字体和样式的文件,并在我的样式表中正确引用了它们。

我使用@font-face 来引用样式表中的字体:

@font-face {
font-family: 'fontname';
src: url('/fonts/webfonts/font.eot');
src: url('/fonts/webfonts/font.eot?#iefix') format('embedded-opentype'),
    url('/fonts/webfonts/font.woff') format('woff'),
    url('/fonts/webfonts/font.ttf') format('truetype');
font-weight: normal;
font-style: normal;
} 

但是,网页字体没有加载到网站中。

经过一番研究,我发现我们需要在 web.config 类型中添加 mime 类型,以便 windows 服务器识别该字体格式。然后,我还在 web.config 文件中引用了 mime 类型如下:

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

但是,它也不起作用。谁能告诉我,我们如何加载这些字体。

【问题讨论】:

    标签: asp.net fonts web hosting


    【解决方案1】:

    所以你还需要为.eot.ttf添加一个MIME映射?

    我们在Web.config 文件中的类似块为:

    <staticContent>
        <remove fileExtension=".svg"/>
        <remove fileExtension=".ttf"/>
        <remove fileExtension=".otf"/>
        <remove fileExtension=".woff"/>
        <remove fileExtension=".eot"/>
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml"/>
        <mimeMap fileExtension=".ttf" mimeType="application/x-font-truetype"/>
        <mimeMap fileExtension=".otf" mimeType="application/x-font-opentype"/>
        <mimeMap fileExtension=".woff" mimeType="application/x-font-woff"/>
        <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject"/>
    </staticContent>
    

    请注意,我们首先删除所有映射,以防它们在某些时候被上游配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-13
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      • 2020-11-16
      • 1970-01-01
      • 2012-03-14
      相关资源
      最近更新 更多