title: Serve video file to iPhone from ASP.NET MVC2
body: <p>I'm attempting to serve video files from ASP.NET MVC to iPhone clients. The video is formatted properly, and if I have it in a publicly accessible web directory it works fine.</p>
  
  <p>The core issue from what I've read is that the iPhone requires you to have a resume-ready download environment that lets you filter your byte ranges through HTTP headers. I assume this is so that users can skip forward through videos.</p>
  
  <p>When serving files with MVC, these headers do not exist. I've tried to emulate it, but with no luck. We have IIS6 here and I'm unable to do many header manipulations at all. ASP.NET will complain at me saying "<strong><em>This operation requires IIS integrated pipeline mode.</em></strong>"</p>
  
  <p>Upgrading isn't an option, and I'm not allowed to move the files to a public web share. I feel limited by our environment but I'm looking for solutions nonetheless.</p>
  
  <p>Here is some sample code of what I'm trying to do in short...</p>
  
  <pre><code>public ActionResult Mobile(string guid = "x")
  {
      guid = Path.GetFileNameWithoutExtension(guid);
      apMedia media = DB.apMedia_GetMediaByFilename(guid);
      string mediaPath = Path.Combine(Transcode.Swap_MobileDirectory, guid + ".m4v");
  
      if (!Directory.Exists(Transcode.Swap_MobileDirectory)) //Make sure it's there...
          Directory.CreateDirectory(Transcode.Swap_MobileDirectory);
  
      if(System.IO.File.Exists(mediaPath))
          return base.File(mediaPath, "video/x-m4v");
  
      return Redirect("~/Error/404");
  }
  </code></pre>
  
  <p>I know that I need to do something like this, however I'm unable to do it in .NET MVC. <a href="http://dotnetslackers.com/articles/aspnet/Range-Specific-Requests-in-ASP-NET.aspx" rel="noreferrer">http://dotnetslackers.com/articles/aspnet/Range-Specific-Requests-in-ASP-NET.aspx</a></p>
  
  <p>Here is an example of an HTTP response header that works:</p>
  
  <pre><code>Date    Mon, 08 Nov 2010 17:02:38 GMT
  Server  Apache
  Last-Modified   Mon, 08 Nov 2010 17:02:13 GMT
  Etag    "14e78b2-295eff-4cd82d15"
  Accept-Ranges   bytes
  Content-Length  2711295
  Content-Range   bytes 0-2711294/2711295
  Keep-Alive  timeout=15, max=100
  Connection  Keep-Alive
  Content-Type    text/plain
  </code></pre>
  
  <p>And here is an example of one that doesn't (this is from .NET)</p>
  
  <pre><code>Server  ASP.NET Development Server/10.0.0.0
  Date    Mon, 08 Nov 2010 18:26:17 GMT
  X-AspNet-Version    4.0.30319
  X-AspNetMvc-Version 2.0
  Content-Range   bytes 0-2711294/2711295
  Cache-Control   private
  Content-Type    video/x-m4v
  Content-Length  2711295
  Connection  Close
  </code></pre>
  
  <p>Any ideas? Thank you.</p>