我有一个windows azure部署(一个web角色),根据请求将一对视频文件(mov和mp4)从azure存储器中拉入它自己的本地IIS存储器,然后我可以通过浏览器访问它。
这可能听起来很愚蠢,但我有充分的理由这样做。
不幸的是,我无法访问mp4文件。 mov很好,但mp4给我“404 - 找不到文件或目录。”
我已经调查了这一点,似乎是因为IIS不会返回未知的文件类型,而mp4必须属于这一类。如果它是一个普通的IIS服务器,我将能够注册mp4 mime类型,但我不知道如何在Windows Azure中进行此操作。
我可以RDP并手动完成,但这不可行,因为角色经常被替换,并且意味着我需要每次都手动重新进行。必须通过其中一个配置文件或代码完成。
有人可以帮忙吗?
谢谢!!
史蒂芬
你能否在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>
希望这可以帮助。
<staticContent>
<remove fileExtension=".mp4"/>
<mimeMap fileExtension=".mp4" mimeType="video/mp4" />
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
要配置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时,选择“添加配置转换”:
在web.Release.config文件中将其添加到de配置标记中:
<system.webServer xdt:Transform="Insert"> <staticContent> <mimeMap fileExtension=".mp4" mimeType="video/mp4" /> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" /> </staticContent> </system.webServer>
有关播放MP4 MIME类型视频的具体问题的答案。