首页 文章

mimeMap无法在Azure网站中使用

提问于
浏览
0

我有一个Azure网站,由几个虚拟应用程序组成 . 根应用程序具有SPA(角度)的URL重写规则:

<rule name="AngularJS" stopProcessing="true">
  <match url=".*"/>
  <conditions  logicalGrouping="MatchAll">
    <!--Is not file-->
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
    <!--Is not directory-->
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
    <!--Is not /api-->
    <add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
    <!--Is not *.extension-->
    <add input="{URL}" pattern="^.*\.(ashx|axd|css|gif|png|mov|MOV|avi|ttf|jpg|jpeg|js|flv|f4v|woff|woff2|json)$" negate="true"/>
  </conditions>
  <action type="Rewrite" url="/"/>
</rule>

根应用程序还有一个非常小的OWIN / Katana中间件应用程序,它运行静态文件中间件以根据条件返回单个页面 . RAMMFAR已关闭,因此静态文件中间件仅用于返回主页 .

我的问题是我有.woff,.woff2和.json文件拒绝在Azure中加载,但在本地IIS中加载正常 . 我有一个web.config具有以下内容:

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

    <remove fileExtension=".woff2"/>
    <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2"/>

    <remove fileExtension=".json"/>
    <mimeMap fileExtension=".json" mimeType="application/json"/>
  </staticContent>
</system.webServer>

这在Azure中不起作用 . 它适用于本地,但不适用于Azure . 我甚至将web.configs放在文件所在的每个文件夹中,以确保不会覆盖规则 . 我认为这可能与在Azure网站中使用虚拟应用程序有关,但我无法更改我的网站结构 . 如何正确地提供这些.woff,.woff2和静态json文件? edit: just checked IIS logs and have found failed request tracing for one of the files. I'm getting a "SECURITY_DENIED_BY_MIMEMAP" error, which means it is something to do with the web.config not getting picked up by IIS.

TLDR: even though I have the appropriate web.config (as far as I know), woff, json, and woff2 files are returning 404 even though they exist on the server in the specified location.

1 回答

  • 0

    如果您使用的是OWIN / Katana,则需要处理静态文件 - 添加Nuget Microsoft.Owin.StaticFiles Install-Package Microsoft.Owin.StaticFiles .

相关问题