ASP.NET MVC4 Source URL for HTML5 Video

In my ASP.NET MVC 4, I want to stream video using HTML5 <video> . The video is saved in this place D:\movie\test.mp4 .

How to place this location as the source of the <video> ? I tried:

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

but does not work. If I add files to 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 to associate a source with a local file without placing it in a project?

Also, should media files be submitted to IIS? What is the best practice for this, it is assumed that the location of the media is pulled from a table in the database?

+4
source share
1 answer

What is the correct way to associate a source with a local file without having to add it to the project?

Unable to access arbitrary files on the server from the client. Imagine the huge security vulnerability that would be created if it were possible.

Access to files that are part of the web application are available only. If you absolutely need access to some arbitrary files, you will need to write a controller action that will transfer the file to the client:

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

and then specify the source tag for this action:

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

Source: https://habr.com/ru/post/1488012/


All Articles