Windows Azure - 如何在Windows Azure IIS存储中服务未知的(mp4) MIME类型

18
我有一个Windows Azure部署(一个Web角色),在请求时从Azure存储中获取一对视频文件(mov和mp4)到它自己的本地IIS存储中,然后通过浏览器访问。虽然这样做可能听起来很愚蠢,但我有充分的理由。不幸的是,我不能访问mp4文件。mov是可以的,但mp4会出现“404-文件或目录未找到”的错误。我已经研究了一下,似乎是因为IIS不会返回未知的文件类型,而mp4必须属于这个类别。如果这是一个普通的IIS服务器,我就可以注册mp4的MIME类型,但我不知道如何在Windows Azure中进行操作。我可以通过远程桌面连接手动完成它,但这并不实际,因为该角色经常被替换,这意味着每次都需要重新手动完成。必须通过其中一个配置文件或代码完成。有人能帮忙吗?谢谢!! Steven
4个回答

14

您是否不能在web.config中添加自定义MIME类型?我刚刚遇到了这个链接:

http://www.iis.net/ConfigReference/system.webServer/staticContent/mimeMap

相关的web.config XML为:

<configuration>
   <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".syx" mimeType="application/octet-stream" />
         <mimeMap fileExtension=".tab" mimeType="text/plain" />
      </staticContent>
   </system.webServer>
</configuration>
希望这有所帮助。

1
做到了,谢谢。在提问之前我确实进行了很多谷歌搜索,但可能使用的搜索词不对! - Steven Elliott
这个可以添加到 app.config 而不是 web.config 吗? - Jason
只是为了补充这个非常好的答案,如果你正在使用react,在以下方式中将此web.config复制到构建文件夹中(使用npm react build)(感谢Liviu Costea):https://medium.com/hackernoon/adding-web-config-to-react-projects-3eb762dbe01f - Luis Gouveia

4

3
要配置MIME类型,请在视频文件夹中创建一个新的web.config文件,并使用以下内容填充:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
     <staticContent>
        <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
     </staticContent>
  </system.webServer>
</configuration>

这个解决方案仅适用于Azure,本地项目可能不再起作用。我的解决方案是在发布时使用“添加配置转换”,对于本地项目使用一个空的web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>
当您右键单击web.config时,选择“添加配置转换”:

enter image description here

在 web.Release.config 文件中,将以下内容添加到 configuration 标签中:
<system.webServer xdt:Transform="Insert">
  <staticContent>
    <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
  </staticContent>
</system.webServer>

谢谢,我一开始没有将它添加到同一个文件夹中,我只是更新了现有的web.config,但这并没有解决我的问题。现在它运行得很好! - Augustin Bocken

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接