ASP.Net Core: Slow Start of File (Video) Download in Internet Explorer 11 and Edge

While experimenting with the <video> tag on an HTML page with a web API endpoint as the source (ASP.NET Core 2.1.1), I noticed that the (not auto-playing) videos

  • appeared immediately in Chrome and Firefox,
  • but took a few seconds in Internet Explorer and Edge to show up on the page.

This is what the code in my controller looked like:

[HttpGet("{id}")] // api/video/example
public IActionResult GetVideoByName(string id)
{
	// ...

	var path = Path.Combine(@"D:\Example\Videos", id + ".mp4");
	return File(System.IO.File.OpenRead(path), "video/mp4");
}

Searching the web for the obvious keywords (IE11, ASP.NET Core, file, stream, slow, download, etc.) yielded lots of results for all kinds of problems. In the end I found out that I needed to enable something called “range processing” (pardon my ignorance, I’m more of a UI guy than a networking expert).

Fortunately, ASP.NET Core 2.1 offers a (new) overload for the File() function with a boolean parameter aptly named enabledRangeProcessing. So the solution is to set that parameter to true:

	return File(System.IO.File.OpenRead(path), "video/mp4", true);

No Comments