4

In my ASP.NET MVC 4, I want to stream video by using the HTML5 <video>. The video is stored at this location D:\movie\test.mp4.

How can I put this location as source to the <video> tag? I tried:

<source src="@Url.Content(@"D:\movie\test.mp4")" type="video/mp4" />

but not working. If I add the files into my project, and do it like this, <source src="@Url.Content("~/Script/test.mp4")" type="video/mp4" /> it will work.

What is the correct way of linking the source to the local file without having to put it in the project?

Also, should the media files be served in the IIS? What is the best practice for this, supposed that the location of the media is pulled of a table in a database?

4

1 回答 1

7

将源链接到本地​​文件而不必将其放入项目中的正确方法是什么?

无法从客户端访问服务器上的任意文件。想象一下,如果可能的话,将会产生巨大的安全漏洞。

您只能访问属于 Web 应用程序一部分的文件。如果您绝对需要访问一些任意文件,那么您将需要编写一个控制器操作,将文件流式传输到客户端:

public ActionResult Video()
{
    return File(@"D:\movie\test.mp4", "video/mp4");
}

然后将源标记指向此操作:

<source src="@Url.Action("Video")" type="video/mp4" />
于 2013-06-25T07:15:29.373 回答