简体   繁体   English

用于HTML5视频的ASP.NET MVC4媒体源URL

[英]ASP.NET MVC4 Media Source Url for HTML5 Video

In my ASP.NET MVC 4, I want to stream video by using the HTML5 <video> . 在我的ASP.NET MVC 4中,我想使用HTML5 <video>来流式传输视频。 The video is stored at this location D:\\movie\\test.mp4 . 视频存储在此位置D:\\movie\\test.mp4

How can I put this location as source to the <video> tag? 如何将此位置作为<video>标记的来源? 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. 如果我将文件添加到我的项目中,并按照这样做, <source src="@Url.Content("~/Script/test.mp4")" type="video/mp4" />它将起作用。

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? 此外,媒体文件应该在IIS中提供吗? What is the best practice for this, supposed that the location of the media is pulled of a table in a database? 这样做的最佳做法是什么,假设媒体的位置是从数据库中的表中提取的?

What is the correct way of linking the source to the local file without having to put it in the project? 将源链接到本地​​文件而不必将其放入项目中的正确方法是什么?

There's no way to access arbitrary files on the server from the client. 无法从客户端访问服务器上的任意文件。 Just imagine the huge security vulnerability that would create if it was possible. 想象一下如果可能的话,会产生巨大的安全漏洞。

You can only access files that are part of the web application. 您只能访问属于Web应用程序的文件。 If you absolutely need to access some arbitrary files, then you will need to write a controller action that will stream the file to the client: 如果您绝对需要访问某些任意文件,那么您需要编写一个控制器操作,将文件流式传输到客户端:

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

and then point the source tag to this action: 然后将源标记指向此操作:

<source src="@Url.Action("Video")" type="video/mp4" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM