ASP.NET MVC不提供MP3文件 [英] ASP.NET MVC Not Serving MP3 Files

查看:70
本文介绍了ASP.NET MVC不提供MP3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网站上播放mp3文件作为背景音乐.为此,我在Content中创建了一个名为mp3的文件夹,并将文件添加到其中.我使用的html看起来像

I am trying to play an mp3 file as background music on a website. To serve it I created a folder called mp3 in Content and added the file to it. The html I use looks like

<audio loop="loop" autoplay="autoplay">
  <source src="/mp3/myfile.mp3" type="audio/mp3" />
</audio>

浏览器返回404,是..我验证了文件名正确,甚至将其重命名为"a.mp3",以确保其中没有发生任何有趣的事情.

The browser returns a 404 and yes.. I verified the name of the file is correct and even renamed it to "a.mp3" to make sure nothing funny was happening there.

如果我在新标签"中选择打开",我也会得到404.(即mydomain.com/mp3/a.mp3给出了404)

If I select Open in New Tab I also get 404. (i.e. mydomain.com/mp3/a.mp3 gives a 404)

作为一个实验,我在mp3文件夹中放置了一个js文件(.mydomain,com/mp3/test.js),并且可以毫无问题地将其放到新标签页中.还将png文件放在文件夹(mydomain.com/mp3/pic.png)中,可以正常使用.将其复制到正在使用的另一个文件夹(如js或css)中,将得到相同的结果.我可以提供文件夹中的js或css文件,但如果尝试检索mp3文件,则会得到404.

As an experiment I placed a js file in the mp3 folder.. (mydomain,com/mp3/test.js) and it is served into a new tab with no problem. Also placed a png file in the folder (mydomain.com/mp3/pic.png) and it is served with no problem. Copying it to another folder in use like js or css gives same result. I can serve up the js or css files in the folder but get a 404 if I try to retrieve the mp3 file.

FF和Chrome的结果相同,因此它不是特定于浏览器的.

Same results with FF and Chrome so it is not browser specific.

似乎是某些特定原因导致它拒绝提供mp3文件.

It seems something is specifically causing it to refuse to serve mp3 files.

顺便说一句,我还在Windows桌面上打开了文件,它们在WMP中播放没有问题,因此文件没有任何问题.

BTW I also opened the files on my windows desktop and they play with no problem in WMP so there is nothing wrong with the files.

推荐答案

我终于找到了问题所在.我意识到,尽管MVC处理程序具有静态文件映射,但是所有请求仍将通过ASP.NET MVC路由器进行.

I finally figured out the problem. I realized that although there was a static file mapping for the MVC Handler, that any requests would still go through the ASP.NET MVC router.

结果是,我定义了一个自定义路由,出于安全原因,它锁定了它将提供的文件类型,而mp3并不是其中之一.

Turns out I had a custom route defined that for security reasons locked down the file types it would serve and mp3 wasn't one of them.

这篇关于ASP.NET MVC不提供MP3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆