简体   繁体   中英

mimeMap not working in Azure Website

I have an Azure website that consists of several virtual applications. The root application has URL rewrite rules for a SPA (angular):

<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>

The root application also has a very small OWIN/Katana middleware application that runs the static files middleware to return a single page based on a condition. RAMMFAR is turned off and thus the static files middleware is only used to return the homepage.

My problem is that I have .woff, .woff2, and .json files that refuse to load in Azure, but load fine in local IIS. I have a web.config that has the following:

<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>

This does NOT work in Azure. It works well locally, but not in Azure. I've even put web.configs in each folder that the files reside in to make sure the rules are not overwritten. I think it may be related to using virtual applications within an Azure Website, but I cannot change my site structure. How can I make these .woff, .woff2, and static json files be served properly? 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.

There is only a single way to do this currently, and I confirmed this with the Azure team.

Add a web.config file to the root of the application wwwroot\\web.config with the following contents

  <?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <system.webServer>
      <staticContent>
        <mimeMap fileExtension=".mp4" mimeType="application/mp4" />
        <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
        <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
      </staticContent>
    </system.webServer>
  </configuration>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM