在 web.config 中为 IIS Express 添加 MIME 映射 [英] Add MIME mapping in web.config for IIS Express
问题描述
我需要为 IIS Express 的 .woff 文件扩展名添加一个新的 MIME 映射.
I need to add a new MIME mapping for .woff file extensions to IIS Express.
如果我将以下代码段添加到 IIS Express 的applicationhost.config"中,它就可以正常工作:
If I add the following snippet to the "applicationhost.config" of IIS Express it works fine:
<staticContent lockAttributes="isDocFooterFileName">
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />
...
但我实际上希望将它添加到我的web.config"中,这样不是每个开发人员都需要在本地更改他们的applicationhost.config".
But I would actually like to do add it to my "web.config" so that not every developer would need to change their "applicationhost.config" locally.
所以我再次从applicationhost.config"文件中删除它,并将以下代码段添加到项目的web.config"中:
So I removed it again from the "applicationhost.config" file and added the following snippet to the project's "web.config":
<system.webServer>
...
<staticContent>
<mimeMap fileExtension=".woff" mimeType="font/x-woff" />
</staticContent>
</system.webServer>
不幸的是,它似乎不能那样工作,因为当我尝试访问 .woff 文件时,我最终遇到了 HTTP 404.3 错误.
Unfortunately it doesn't seem to work that way because when I try to access a .woff file I end up with a HTTP 404.3 error.
我做错了什么?
推荐答案
将它放在web.config"中工作正常.问题是我弄错了 MIME 类型.而不是 或 font/x-woff
它必须是 <代码>应用程序/字体woff:font/x-font-woff
Putting it in the "web.config" works fine. The problem was that I got the MIME type wrong. Instead of or font/x-woff
it must be font/x-font-woff
application/font-woff
:
<system.webServer>
...
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</staticContent>
</system.webServer>
另请参阅有关 MIME 类型的答案:https://stackoverflow.com/a/5142316/135441
See also this answer regarding the MIME type: https://stackoverflow.com/a/5142316/135441
2013 年 4 月 10 日更新
Spec 现在是推荐标准,MIME 类型正式为:application/font-woff
Spec is now a recommendation and the MIME type is officially:
application/font-woff
这篇关于在 web.config 中为 IIS Express 添加 MIME 映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!