0

I have a mvc4 application serving my HTML 5 code to the client. I am using the HTML 5 video tag to show a video. Usually I would put the video file into my application root directory to access it, but now I want to implement another scenario. My root directory for my app is i.e. C:\MyApp while the video file is in the directory C:\VideoDir.

Now I want to use the video tag and pass it an url as source that looks like

http://myurl/MyApp/Media/Video/test.mp4

I need to find a way to redirect this URL to the actual videofile inside of the VideoDir without expose the VideoDir via http to the public. The reason for this approach is, that I want to check permissions before serving the video. If I would expose the VideoDir to public via http, anyone who knows the baseurl would be able to watch any video s/he wants to.

I tested a bit with FileContentResult, FilePathResult and FileStreamResult. Chrome can handle the result, but it is not possible to seek and even worst the video tag of iOS's Safari cannot consume these results, while it could consume the original .mp4 file.

Any idea or suggestions?

ssilas777
  • 9,672
  • 4
  • 45
  • 68
Kevkong
  • 460
  • 3
  • 16
  • Hey, I did not accept your answer yet, because as it seems I have another better solution and will provide this solution here as soon as I am done with it. Sorry, had several other things to do these days. – Kevkong May 21 '13 at 11:04

2 Answers2

0

In IIS, Add Virtual Directories inside you App Folder with the name of following

Medias

Now you can access the Video File like below

http://myurl/MyApp/Media/Video/test.mp4

NOTE - Please add the Virtual Directory inside App and Name the Virtual Directory Medias which will point to VideoDir

Hope this will help you

  • I considered this solution too, but there is a big problem with this solution. I can not run my security stuff (checking permissions) before the user access the file. So the result is: Everyone who knows the URL (you can simply find it with developer tools like firebug or fiddler) can access the video files s/he wants to. – Kevkong May 15 '13 at 08:25
  • FireBug or Fiddler can tell about only the current video(http://myurl/MyApp/Media/Video/test.mp4) being downloaded. How can Fiddler tell about the other videos placed in the same directory ? –  May 15 '13 at 09:22
  • Of course FireBug or Fiddler can not tell you about the other video files located in the folder but if there is a naming convention, it should be very easy to find the other files. Is there at least a possibility to restrict the access of a file to a specific session or something like that? – Kevkong May 15 '13 at 09:37
  • Why don't u use GUID names ? –  May 15 '13 at 09:37
  • Because the files are created by another application. Maybe I should create a copy of the requested file, using a session related name and serve it to the user. But I think copying the file (especially if it is a huge file) will take some time. – Kevkong May 15 '13 at 09:54
  • @Kevkong Preventive Action - Start using GUID. Corrective Action - Start copying the files with GUID names as much as you can. –  May 15 '13 at 10:53
  • @Kevkong - Also, can you rename the existing files with GUID ? –  May 15 '13 at 10:54
  • Nope, because my application is not the only one, which wants to access the files. – Kevkong May 15 '13 at 10:56
  • @Kevkong - You are right, somebody can guess the file and can download/access it. That's the reason you need some name which should not be able to be guessed and that is GUID. –  May 15 '13 at 10:59
0

After looking at the headers send by the <video> tag I found out that the solution to this problem would be to handle range requests. To sum it up: My question is kind of a duplicate question to this one: c# streaming over http to iphone

To make this work with mvc4 you need to ignore the *.mp4 extension so it is handled by your own handler and not by mvc4. Just execute the following line inside your RegisterRoutes method:

routes.IgnoreRoute("{file}.mp4");

or the following in your Application_Start method:

RouteTable.Routes.IgnoreRoute("{file}.mp4");

(credits to: Using ASP.NET routing to serve static files)

Community
  • 1
  • 1
Kevkong
  • 460
  • 3
  • 16