MVC Serve audio files while preventing direct linking using HttpResponseBase
Posted
by
VinceGeek
on Stack Overflow
See other posts from Stack Overflow
or by VinceGeek
Published on 2011-01-02T16:42:05Z
Indexed on
2011/01/02
16:54 UTC
Read the original article
Hit count: 208
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.
© Stack Overflow or respective owner