Comments on: Easy Handling of Http Range Requests in ASP.NET https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/ Tips on .Net, SQL Server, Sharepoint & AI Mon, 17 Oct 2022 22:48:07 +0000 hourly 1 https://wordpress.org/?v=6.3.5 By: Streaming MP4 video through .NET HTML5 https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38879 Mon, 17 Oct 2022 22:48:07 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38879 […] And another helpful post from Chris Coulson which provided the implementation in C# for the solution! http://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/ […]

]]>
By: Susantha Soysa https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38854 Thu, 19 Nov 2020 02:18:53 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38854 You are a life saver. Thanks so much for sharing your code. With a small tweak, I managed to get it working for my scenario.

context.Response.WriteFile(fullpath, fp, length);
context.Response.Flush();
context.Response.Close();

Without Flush, my code was throwing an error.

]]>
By: Ali Sheikhpour https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38851 Wed, 28 Oct 2020 12:57:35 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38851 Sorry . I had replaced WriteFile with TransmitFile (to handle large files) And seems it is lokcing the file.

]]>
By: Ali Sheikhpour https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38850 Wed, 28 Oct 2020 12:47:41 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38850 It seem there is some object or streamer which is not closed or Disposed proprly. The files remain in use with w3wp.exe even after the video is was finished.

]]>
By: Serious.Netter https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38839 Sat, 09 May 2020 00:07:59 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38839 this code snippet has saved me lots of time. there is just one thing i thought i should point out.

When using this code to load videos that are a couple Gigs in size.

the second last line

—————
context.Response.WriteFile(fullpath, fp, length);
—————

would throw an error saying length can only be between 0 and Int32.MaxValue. in that case, a file of 2.2Gb would trigger this error.

I have worked around this by sending the data in blocks of 2Mb ( you can customize the block size). The following is my modification. Use it over the line above.

—————
long blockSize = 1024 * 1024 * 2; //2mb
while(length > 0)
{
if(length > blockSize)
{
context.Response.WriteFile(fullpath, fp, blockSize);
context.Response.Flush();
fp += blockSize;
length -= blockSize;
}
else
{
context.Response.WriteFile(fullpath, fp, length);
context.Response.Flush();
fp += length;
length -= length;
}
Thread.Sleep(10);
}
—————

]]>
By: Chris Coulson https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38676 Thu, 30 Nov 2017 17:51:32 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38676 In reply to LeKuchen.

I haven’t tested it, but that does sound like a good enhancement – I would think it would work.

]]>
By: LeKuchen https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38675 Thu, 30 Nov 2017 17:13:27 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38675 Hi Chris,

I use your code for delivering large files. Thanks for the code! Sometimes I do receive an error in the IIS log: not enough storage is available to proccess this command.

Wouldn’t it make sense to use
context.Response.TransmitFile(fullpath, fp, sizeThreshold);
instead of
context.Response.WriteFile(fullpath, fp, sizeThreshold);
to release memory and not buffering the file before writing the file to the output stream?

]]>
By: Chris Coulson https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38651 Wed, 27 Sep 2017 12:12:59 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38651 In reply to xhaxha.

The HttpContext is a variable that’s available when your ASP.NET application is handling a web request. Check the project on Github, there is a sample application showing it’s use:

http://videostreamer.codeplex.com/SourceControl/latest#SampleWebApplication/VideoStreamer.ashx

]]>
By: xhaxha https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38650 Wed, 27 Sep 2017 08:45:12 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38650 Hi, can you please help me by providing an example on how to call this function? I don’t know what is the CONTEXT that I must provide. I am a newbie in this. Thank you very much. Your response will be highly appreciated.

]]>
By: Kirk https://blogs.visigo.com/chriscoulson/easy-handling-of-http-range-requests-in-asp-net/#comment-38494 Fri, 29 Apr 2016 20:41:34 +0000 http://blogs.visigo.com/chriscoulson/?p=97#comment-38494 I think I might have found a small bug in the code. If you look at this particular code

// If the range starts with an ‘-‘ we start from the beginning
// If not, we forward the file pointer
// And make sure to get the end byte if spesified
if (range.StartsWith(“-“))
{
// The n-number of the last bytes is requested
anotherStart = size – Convert.ToInt64(range.Substring(1));
}

I believe you want to set anotherEnd here. From my testing I never saw a request start started with -, but I wanted to point it out since it could cause a problem in some specific case.

]]>