1. 程式人生 > >MVC 無法載入字型檔案(*.woff,*.svg)的解決辦法

MVC 無法載入字型檔案(*.woff,*.svg)的解決辦法

原文出處:http://blog.163.com/ny_lonely/blog/static/18892427320151265526367/

在編寫前端程式碼的過程中經常會遇到使用特定的字型(*.woff,*.svg),此時在載入字型時請求會被返回

Failed to load resource: the server responded with a status of 404 (Not Found)。

原因是,預設在IIS上是沒有新增對*.woff,*.svg檔案的Mime型別,因此在客戶端請求此類檔案時得到的都是404。

所以我們只需要在我們對應網站下的Mime型別中新增檔案對應的型別就行了

  1. .woff  application/x-font-woff
  2. .woff2 application/x-font-woff
  3. .svg   image/svg+xml

另外在mvc中,設定了上述Mime型別後get請求字型時任然會出現404的問題,這個時候需要在我們的web工程中的config的system.webServer節點中新增如下的程式碼來支援

<staticContent>
<removefileExtension=".woff"/>
<mimeMapfileExtension=".woff"mimeType="application/x-font-woff"/>
<removefileExtension=".woff2"

/>
<mimeMapfileExtension=".woff2"mimeType="application/x-font-woff2"/>
<removefileExtension=".ttf"/>
<mimeMapfileExtension=".ttf"mimeType="application/x-font-truetype"/>
<removefileExtension=".svg"/>
<mimeMapfileExtension=".svg"mimeType="image/svg+xml"/>
<removefileExtension=".otf"
/>
<mimeMapfileExtension=".otf"mimeType="application/x-font-opentype"/>
<removefileExtension=".eot"/>
<mimeMapfileExtension=".eot"mimeType="application/vnd.ms-fontobject"/>
</staticContent>