MVC Serve audio files while preventing direct linking using HttpResponseBase
- by VinceGeek
I need to be able to serve audio files to an mvc app while preventing direct access. Ideally the page would render with a player control so the user can start/stop the audio linked to the database record (audio files are in a folder not the db). I have a controller action like this:
Response.Clear();
Response.ContentType = "audio/wav";
Response.TransmitFile(audioFilename);
Response.End();
return Response;
and the view uses the RenderAction method
<% Html.RenderAction("ServeAudioFile"); %>
this works but it won't display inline on the existing view, it opens a new page with just the media control. Am I totally barking up the wrong tree or is there a way to embed the response in the existing view? works exactly as I would like but I can't control access to the file.