1

I have following url

Call/GetAudio/f9715595-a540-4add-8419-f9cdf906c7ec.mp3

Now the problem is the above .mp3 file does not actually exist, rather I want it to go to "CallController", "GetAudio" function which will then return the bytes array as FileResult.

I imagine I need to configure some routing for this in global.asax, is this achievable?

Basically I want all .mp3 files to go through routing.

tereško
  • 58,060
  • 25
  • 98
  • 150
friend
  • 1,909
  • 2
  • 21
  • 28
  • just serve the .mp3 file type through your controller. Then you can drop the `.mp3` file extension since the controller will be serving only mp3's. Your routing will be a normal route `{Controller}/{Action}/{id}` – Chase Florell Nov 14 '11 at 00:54

2 Answers2

1

All paths will go through routing, regardless of extension.
(assuming IIS is correctly configured to use ASP.Net as a wildcard handler)

Just make a normal route.

Note that there is no reason to include .mp3 in the URL; just make sure to include an appropriate Content-Type in the response, which you should do regardless of URL.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Yes, I know there's no reason to include .mp3 file (or any extension in url). However, I need this for very specific purpose - I am developing jquery player + jquery mobile for Android, and from what i gather it needs the .mp3 file to force android to download the file, otherwise it thinks that the url is invalid and will not even attempt to download it - thus jquery player cannot play the file since it's not downloaded. – friend Nov 14 '11 at 03:18
  • Like you said, I got IIS error saying "file not found" when trying the url. Is conguring IIS the only way to achieve this? – friend Nov 14 '11 at 03:20
  • IIS should be configured to use ASP.Net for all requests. If it isn't, you should fix that. – SLaks Nov 14 '11 at 03:30
  • 1
    However, that sounds unlikely. Android should be reading the `Content-Type`, not the URL extension. – SLaks Nov 14 '11 at 03:31
  • I have done more testing, and yeah it's nothing to do with the extension - it was actually security thing. Seems like even after the user is logged in, when jplayer tried to download the mp3 file - it either fires different session or somehow thinks that the user is not logged in. Very weird, even though it works perfectly fine on iPhone. – friend Nov 14 '11 at 05:56
0

Here's a similar answer, only it's serving images instead of audio files, however the principles are the same.
Can an ASP.NET MVC controller return an Image?

Simply create a Controller Action that serves MP3's. Then you can drop the .mp3 file extension since the controller will be serving only mp3's. Your routing will be a normal route {Controller}/{Action}/{id}

Community
  • 1
  • 1
Chase Florell
  • 46,378
  • 57
  • 186
  • 376
  • Sorry, this does not answer my question. The other post wanted url without extension to return image that physically exist - while I need the url with .mp3 extension - to trick android/jquery player per my other comment to SLaks answer. – friend Nov 14 '11 at 03:24
  • SLaks comment is spot on `However, that sounds unlikely. Android should be reading the Content-Type, not the URL extension. ` – Chase Florell Nov 14 '11 at 04:07