0

I wrote a basic range request class I was wanting to flesh out so html5 video and audio players could interact with my MVC app.

I have it functioning (but not fully featured for things like If-Modified) if I don't add the extension to the 'src' tags. Thing is on the routing I can't get any string with a "{filename}.{extension}" style of route to work. My guess is anything like that is assumed to be a static file and thus I never get the opportunity to fulfill the request. If I add a source without the extension it works.

So this works

<video id="my-video-player" class="video-js" controls preload="auto" width="640" height="264" src="@Url.Action("Index","Video",new { id = "SampleVideo_1280x720_20mb" })" type="video/mp4">
    <p class="vjs-no-js">
        To view this video please enable JavaScript, and consider upgrading to a web browser that
        <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
    </p>
</video>

but this doesn't

<video id="my-video-player" class="video-js" controls preload="auto" width="640" height="264" src="@Url.Action("Index","Video",new { id = "SampleVideo_1280x720_20mb.mp4" })" type="video/mp4">
    <p class="vjs-no-js">
        To view this video please enable JavaScript, and consider upgrading to a web browser that
        <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
    </p>
</video>

Does anyone know how I could make certain extensions potentially reroute to a handler of my choosing?

Edit:

Linked below is a method to make it work on 1 path, ideally I'd like to inject it so I could do it for any path, so I'd like to keep it open to see if anyone has more insight. As this method still would require you to have an IgnorePath also to make sure any direct path to your media files aren't handled by the static file handler instead of your MVC path.

  <system.webServer>
    <handlers>
      <add name="Media-Handler" path="/Video/*" verb="GET" type="System.Web.Handlers.TransferRequestHandler"  preCondition="integratedMode,runtimeVersionv4.0"/>
    </handlers>
  </system.webServer>
Chase R Lewis
  • 2,119
  • 1
  • 22
  • 47
  • 1
    Possible duplicate of [Dots in URL causes 404 with ASP.NET mvc and IIS](https://stackoverflow.com/questions/11728846/dots-in-url-causes-404-with-asp-net-mvc-and-iis) – NightOwl888 Jun 16 '17 at 17:39
  • I've managed to get this to work, but preferably I'd like to inject a handler so I could handle ANY request for video or audio no matter the pathing location. I'd consider that a work around not necessarily a complete solution. – Chase R Lewis Jun 16 '17 at 17:49
  • As the link suggests, you need to add additional `TransferRequestHandler`s in order for IIS to take the `.` into account. The simplest way in your case would be to add one with the path `*.mp4`, which would handle all files with that extension regardless of their physical location. – NightOwl888 Jun 16 '17 at 17:54
  • Hm, that makes sense. Thanks! – Chase R Lewis Jun 16 '17 at 17:56

0 Answers0