如何用流ASP.NET MVC FileStreamResult部分内容 [英] How to stream partial content with ASP.NET MVC FileStreamResult

查看:1570
本文介绍了如何用流ASP.NET MVC FileStreamResult部分内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用FileStreamResult提供视频数据到一个基于Silverlight的MediaElement视频播放器:

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");
}

不幸的是,它开始播放前的Silverlight视频播放器下载整个视频文件。预计此行为作为我们的 preVIEW 动作不支持下载部分内容。

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.

(边注:。如果文件是在IIS虚拟目录托管,我们可以在它的同时仍然在下载视频的任意位置开始播放,但基于安全和审计原因,我们不能提供直接下载链接,这不是一个选项。)

(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.)

如何改善控制器动作来支持部分HTTP内容?

我认为我们首先要告知,我们支持它的客户端(增加一个接受范围:字节头HEAD请求),那么我们必须评估的HTTP范围头和流的pool范围与206的响应code将与ASP.NET MVC的工作托管于IIS6?有没有已经有code可用?

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?

另请参见:

推荐答案

有是codePLEX这给这个确切的功能的项目。

There is a project on CodePlex which gives this exact functionality.

HTTP://mediastreamingmvc.$c$cplex.com/

看一看。有人对于这种情况,你想拥有重新$ P $行动psenting为虚拟资源的请求,如果无需开发人员做很多工作来支持它(结果的措施筛选和选择,以便要求返回部分内容专门创建类型。)

Take a look. It was created specifically for this scenario where you want to have an action representing a request for a virtual resource and return partial content if so requested without requiring the developer to do much to support it (an Action Filter and choice of Result types.)

这篇关于如何用流ASP.NET MVC FileStreamResult部分内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆