Take the 2-minute tour ×

I am designing a web application for iPad which makes use of HTML5 in mobile safari. I am transmitting the file manually through an ASP.NET .ashx file hosted on IIS 7 running .NET Framework v2.0.

The essential code looks partly like this:

// If we receive range header only transmit partial file
if (context.Request.Headers["Range"] != null)
    var fi = new FileInfo(filePath);
    long fileSize = fi.Length;

    // Read start/end index
    string headerRange = context.Request.Headers["Range"].Replace("bytes=", "");
    string[] range = headerRange.Split('-');
    int startIndex = Convert.ToInt32(range[0]);
    int endIndex = Convert.ToInt32(range[1]);

    // Add header Content-Range,Last-Modified
    context.Response.StatusCode = (int)HttpStatusCode.PartialContent;
    context.Response.AddHeader(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderContentRange), String.Format("bytes {0}-{1}/{2}", startIndex, endIndex, fileSize));
    context.Response.AddHeader(HttpWorkerRequest.GetKnownResponseHeaderName(HttpWorkerRequest.HeaderLastModified), String.Format("{0:r}", fi.CreationTime));

    long length = (endIndex - startIndex) + 1;
    context.Response.TransmitFile(filePath, startIndex, length);

Now what confuses me to no end is the the protocols for requesting that safari seems to use. From proxying the requests through fiddler i get the following for an aprox 2MB file.

Fiddler requests

NOTE: When requesting an mp4 file, directly served through IIS 7, the protocol and amount of request are the same

  1. First it requests 2 bytes which allows it to read the 'Content-Range' header.
  2. Now it request the entire content (?)
  3. -
  4. It proceeds to do step 1. & 2. again (??)
  5. -
  6. It now requests only parts of the file (???)

If the file is larger the last steps will be many more. I have tested up to 99 request where each request contains a part of the file equally split. This makes sense and is what would be expected I think. What I cannot make sense of is why it makes 2 initial request for the first 2 bytes as well as 2 requests for the entire file before it finally requests the file in different parts.

As I conclude this results in the file being downloaded between 2 - 3 times, depending on the length of the file and whether the user watches it long enough.

Can anybody make sense of this behavior and maybe explain what I can do to prevent multiple downloads. Thanks.

share|improve this question
i came across the same thing. its also ipod and if you're dealing with mp3 files. no solution unfortunately... –  mightyuhu Jun 17 '11 at 23:08
I have noticed the same with a very large (30meg) video. Sometimes 3 requests for the whole file when the request comes from an iPad! –  Jim Petkus Aug 26 '11 at 21:01
This is called a progressive download. You really should support 206 partial download requests for video files. I don't personally know anything about ASP so I can't give an actual example that I know works, but google for "implementing http 206 download support in ASP" or ask a more specific question related to that, for more details on how to proceed. –  Ryan LaBarre Dec 14 '11 at 21:03
I've had the same experience with mp3 files inside the MPMoviePlayerController. Here's a question I asked about this which went unanswered. My question has a bit more info about the requests being made. stackoverflow.com/questions/4855485/… –  TomSwift Dec 14 '11 at 21:06

1 Answer 1

Per my comment to your question, I've had a similar issue in the past. One thing you could try if you have control of the server (I did not) is to disable either gzip or identity encoding of the file. I believe that in the first request for the entire content (#2 in your list) it asks for the content with gzip encoding (compressed). Perhaps you can configure your IIS to not to serve the file for a gzip-encoding request.

Here is my original (unanswered) question on the subject:

MPMoviePlayerController not playing full length MP3

share|improve this answer

Your Answer


