Skip to content Skip to sidebar Skip to footer

ASP.NET MVC Not Serving MP3 Files

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

Solution 1:

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.

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.


Solution 2:

First, you should check the path with browser's developer tools (view source) to make sure that the file path is rendered properly. Your problem seem occurred because of wrong file path.

Second, instead of creating src path manually, use @Url.Content() helper with relative virtual path to MP3 file like example below, make sure the correct path is used:

<audio loop="loop" autoplay="autoplay">
  <source src="@Url.Content("~/mp3/myfile.mp3")" type="audio/mp3" />
</audio>

If the page is deployed in production server, make sure that MIME type audio/mp3 is enabled in IIS settings and you have read/write permission for /mp3 folder. You may check (and add) this setting inside <system.webServer> section in either applicationHost.config, machine.config or web.config file:

<staticContent>
     <mimeMap fileExtension=".mp3" mimeType="audio/mp3" />
</staticContent>

Post a Comment for "ASP.NET MVC Not Serving MP3 Files"