How to stream partial content with ASP.NET MVC FileStreamResult
Posted
by o_o
on Stack Overflow
See other posts from Stack Overflow
or by o_o
Published on 2009-07-21T08:50:00Z
Indexed on
2010/04/16
8:03 UTC
Read the original article
Hit count: 688
We're using a FileStreamResult to provide video data to a Silverlight MediaElement based video player:
public ActionResult Preview(Guid id) {
return new FileStreamResult(
Services.AssetStore.GetStream(id, ContentType.Preview),
"application/octet-stream");
}
Unfortunately, the Silverlight video player downloads the entire video file before it starts playing. This behavior is expected as our Preview
Action does not support downloading partial content.
(side note: if the file is hosted in an IIS virtual directory we can start playback at any location in the video while it is still downloading. however for security and auditing reasons we can't provide a direct download link. so this is not an option.)
How can we improve the Controller Action to support partial HTTP content?
I assume we first have to inform the client that we support it (adding an "Accept-Ranges:bytes" header to a HEAD request), then we have to evaluate the HTTP "Range" header and stream the requested file range with a response code of 206. Will that work with ASP.NET MVC hosted on IIS6? Is there already some code available?
Also see:
© Stack Overflow or respective owner