擴充 staticContent 節點,讓 IIS 看的懂 HTML5 Video 與 WebFont
- 2013-05-26
- 22113
- 0
如果網頁用到了 Web Font 或是 HTML5 Video Tag 的開發人員在初次將網站放到正式機時會發現原來 IIS 並不認識 ogv 、 webm 、 svg 、 woff 、 eot 、 otf 這些靜態檔案,以往都要去 IIS 設定,不過只要你用的是 IIS7 以上版本,這些事情可以直接在 Web.config 內搞定,本篇文章就是記錄一下必要的調整方式。
如果你執行中的網站還在使用陳年的 IIS6 請考慮更新版本,提高安全性。
本篇沒什麼說明,只是一個記錄。
如果需要使用到 HTML5 的Video Tag 播放影片需要以下設定:
<system.webServer>
<staticContent>
<remove fileExtension=".mp4" />
<remove fileExtension=".ogv" />
<remove fileExtension=".webm" />
<remove fileExtension=".svg" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<mimeMap fileExtension=".ogv" mimeType="video/ogg" />
<mimeMap fileExtension=".webm" mimeType="video/webm" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
</system.webServer>
如果需要使用到 Web font 需要以下設定:
<system.webServer>
<staticContent>
<remove fileExtension=".woff" />
<remove fileExtension=".svg" />
<remove fileExtension=".eot" />
<remove fileExtension=".ttf" />
<remove fileExtension=".otf" />
<mimeMap fileExtension=".woff" mimeType="application/x-woff" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".ttf" mimeType="application/x-font-ttf" />
<mimeMap fileExtension=".otf" mimeType="application/x-font-opentype" />
</staticContent>
</system.webServer>
兩個都要支援的話請自行合併整理。
以上的範例部分的 remove 是不必要的,因為 IIS 中原本就沒註冊,所以不用移除,但是為了確保安全(不知道誰會去動IIS設定)所以還是一律加上 remove 。








Roslyn 魔法工坊:打造你的 Source Generator [2025-12-20]開課 共7H
回應討論